首页 > 其他分享 >xml约束_dtd、schema

xml约束_dtd、schema

时间:2023-01-31 15:46:22浏览次数:37  
标签:xml www itcast cn dtd http schema

xml约束_dtd

DTD:

  引入dtd文档到xml文档中

    内部dtd:将约束规则定义在xml文档中

    外部dtd:将约束规则定义在外部的dtd文件中

      本地:<!DOCTYPE 根标签名 SYSTEM "dtd文件的位置">

      网络:<!DOCTYPE 根标签名 PUBLIC "dtd文件名字" "dtd文件的位置URL">

<!ELEMENT students (student+) >
<!ELEMENT student (name,age,sex)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT age (#PCDATA)>
<!ELEMENT sex (#PCDATA)>
<!ATTLIST student number ID #REQUIRED>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE students SYSTEM "student.dtd">

<!--<!DOCTYPE students [

        <!ELEMENT students (student+) >
        <!ELEMENT student (name,age,sex)>
        <!ELEMENT name (#PCDATA)>
        <!ELEMENT age (#PCDATA)>
        <!ELEMENT sex (#PCDATA)>
        <!ATTLIST student number ID #REQUIRED>


        ]>-->
<students>
    
    <student number="s001">
        <name>zhangsan</name>
        <age>abc</age>
        <sex>hehe</sex>
    </student>

    <student number="s002">
        <name>lisi</name>
        <age>24</age>
        <sex>female</sex>
    </student>
    
</students>

xml约束_schema

 引入:

  1.填写xml文档的根元素

  2.引入xsi前缀. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  3.引入xsd文件命名空间. xsi:schemaLocation="http://www.itcast.cn/xml student.xsd"

  4.为每一个xsd约束声明一个前缀,作为标识 xmlns="http://www.itcast.cn/xml"

    <students xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xmlns="http://www.itcast.cn/xml"

    xsi:schemaLocation="http://www.itcast.cn/xml student.xsd">

<?xml version="1.0"?>
<xsd:schema xmlns="http://www.itcast.cn/xml"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://www.itcast.cn/xml" elementFormDefault="qualified">
    <xsd:element name="students" type="studentsType"/>
    <xsd:complexType name="studentsType">
        <xsd:sequence>
            <xsd:element name="student" type="studentType" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="studentType">
        <xsd:sequence>
            <xsd:element name="name" type="xsd:string"/>
            <xsd:element name="age" type="ageType" />
            <xsd:element name="sex" type="sexType" />
        </xsd:sequence>
        <xsd:attribute name="number" type="numberType" use="required"/>
    </xsd:complexType>
    <xsd:simpleType name="sexType">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="male"/>
            <xsd:enumeration value="female"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="ageType">
        <xsd:restriction base="xsd:integer">
            <xsd:minInclusive value="0"/>
            <xsd:maxInclusive value="256"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="numberType">
        <xsd:restriction base="xsd:string">
            <xsd:pattern value="heima_\d{4}"/>
        </xsd:restriction>
    </xsd:simpleType>
</xsd:schema>
<?xml version="1.0" encoding="UTF-8" ?>
<!-- 
    1.填写xml文档的根元素
    2.引入xsi前缀.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    3.引入xsd文件命名空间.  xsi:schemaLocation="http://www.itcast.cn/xml  student.xsd"
    4.为每一个xsd约束声明一个前缀,作为标识  xmlns="http://www.itcast.cn/xml" 
    
    
 -->
<students   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns="http://www.itcast.cn/xml"
            xsi:schemaLocation="http://www.itcast.cn/xml  student.xsd"
>
    <student number="heima_0001">
        <name>tom</name>
        <age>18</age>
        <sex>male</sex>
    </student>

</students>

标签:xml,www,itcast,cn,dtd,http,schema
From: https://www.cnblogs.com/wsfj/p/17079370.html

相关文章

  • maven的setting.xml核心文件
    settings.xml,这个文件默认在MAVEN_HOME/conf目录,一般我们会拷贝一份放在~/.m2目录中;MAVEN_HOME/conf/settings.xml是全局范围的配置文件,整个机器上所有用户都会受到该配置......
  • XML概述和快速入门
    XML概述概念:Extensible  Markup  Language 可扩展标记语言可扩展:标签都是自定义的。功能:存储数据配置文件在网络中传输xml与h......
  • xml Configuration File的Spring Config没有(2021版本的idea)
    1.查看是否下载了spring2.在pom文件中引入spring依赖3.更新maven4.此时还没有显示的话,点击setting查看maven的路径,建议不要使用系统默认的路径因为这样的话,下载的十分......
  • 使用tinyxml2读取ATML测试数据
    源代码如下:#include<windows.h>#include"tinyxml2.h"#include<stdio.h>#include<string>#include<vector>//usingnamespacestd;usingnamespacetinyxml2;......
  • Fitter-细节-web.xml配置方式 Fitter-细节-执行流程&生命周期
    Fitter-细节-web.xml配置方式咱们先把之前写的那个FitterDemo1里面的那个WebFitter注解,注释掉才可以写web.xml<?xmlversion="1.0"encoding="UTF-8"?><web-appxmlns......
  • MyBatis的Mapper.xml文件中处理大于号小于号的方法
    由于xml中">"和"<"都是有特殊意义的,所以sql语句中不能再使用">"和"<"符号,就需要进行处理.比如:select*fromt_docwherecreate_time<'2023-01-3011:00:00'方式......
  • XmlSerializer 反序列化学习
    XmlSerializer反序列化漏洞https://www.cnblogs.com/nice0e3/p/16942833.html#%E5%88%A9%E7%94%A8%E9%93%BE%E8%B0%83%E8%AF%95https://www.anquanke.com/post/id/17231......
  • XMLSpy2006企业版汉化特别版
    XMLSpy2006企业版汉化特别版:​​http://soft.studa.com/Download.asp?ID=10255&sID=0​​我用迅雷速度可以达到约:180K/S 另外:MSXMLNotepad:​​http://www.soft666.com/s......
  • Filter细节web.xml配置方式以及执行流程&生命周期
    Filter细节web.xml配置方式<?xmlversion="1.0"encoding="UTF-8"?><web-appxmlns="http://xmlns.jcp.org/xml/ns/javaee"xmlns:xsi="http://www.w3.org/200......
  • Office OpenXML 解析(二):字体
    在OpenXML文档中,字符的字体由RunFonts元素指定,如下所示:<w:rw:rsidRPr="001B7601">//Run<w:rPr><w:rFontsw:hint="eastAsia"w:ascii="TimesNewRo......