标签:程序 value use val 指令 amp 图片 ace 编码方式
1 <?xml version="1.0" encoding="utf-8" standalone=‘no‘ ?> 2 <!--<?xml-stylesheet type="text/css" href="a.css" ?>--> 3 4 <users> 5 6 <user id=‘1‘> 7 <name>张三</name> 8 <age>23</age> 9 <gender>male</gender> 10 <br/> 11 </user> 12 13 <user id=‘2‘> 14 <name>lisi</name> 15 <age>24</age> 16 <gender>female</gender> 17 18 <code> 19 <!-- if(a < b && a > c){}--> 20 <![CDATA[ 21 if(a < b && a > c) {} 22 ]]]> 23 24 25 </code> 26 27 </user> 28 29 </users>
1 <!ELEMENT students (student+) > 2 <!ELEMENT student (name,age,sex)> 3 <!ELEMENT name (#PCDATA)> 4 <!ELEMENT age (#PCDATA)> 5 <!ELEMENT sex (#PCDATA)> 6 <!ATTLIST student number ID #REQUIRED>
dtd文件在XML文件中的引入和使用:student.xml
1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE students SYSTEM "student.dtd"> 3 4 <!--<!DOCTYPE students [ 5 6 <!ELEMENT students (student+) > 7 <!ELEMENT student (name,age,sex)> 8 <!ELEMENT name (#PCDATA)> 9 <!ELEMENT age (#PCDATA)> 10 <!ELEMENT sex (#PCDATA)> 11 <!ATTLIST student number ID #REQUIRED> 12 13 14 ]>--> 15 <students> 16 17 <student number="s001"> 18 <name>zhangsan</name> 19 <age>abc</age> 20 <sex>hehe</sex> 21 </student> 22 23 <student number="s002"> 24 <name>lisi</name> 25 <age>24</age> 26 <sex>female</sex> 27 </student> 28 29 </students>
Schema的引用和使用举例:(了解)
xsd文件的创建:
student.xsd
1 <?xml version="1.0"?> 2 <xsd:schema xmlns="http://www.itcast.cn/xml" 3 xmlns:xsd="http://www.w3.org/2001/XMLSchema" 4 targetNamespace="http://www.itcast.cn/xml" elementFormDefault="qualified"> 5 <xsd:element name="students" type="studentsType"/> 6 <xsd:complexType name="studentsType"> 7 <xsd:sequence> 8 <xsd:element name="student" type="studentType" minOccurs="0" maxOccurs="unbounded"/> 9 </xsd:sequence> 10 </xsd:complexType> 11 <xsd:complexType name="studentType"> 12 <xsd:sequence> 13 <xsd:element name="name" type="xsd:string"/> 14 <xsd:element name="age" type="ageType" /> 15 <xsd:element name="sex" type="sexType" /> 16 </xsd:sequence> 17 <xsd:attribute name="number" type="numberType" use="required"/> 18 </xsd:complexType> 19 <xsd:simpleType name="sexType"> 20 <xsd:restriction base="xsd:string"> 21 <xsd:enumeration value="male"/> 22 <xsd:enumeration value="female"/> 23 </xsd:restriction> 24 </xsd:simpleType> 25 <xsd:simpleType name="ageType"> 26 <xsd:restriction base="xsd:integer"> 27 <xsd:minInclusive value="0"/> 28 <xsd:maxInclusive value="256"/> 29 </xsd:restriction> 30 </xsd:simpleType> 31 <xsd:simpleType name="numberType"> 32 <xsd:restriction base="xsd:string"> 33 <xsd:pattern value="heima_\d{4}"/> 34 </xsd:restriction> 35 </xsd:simpleType> 36 </xsd:schema>
xsd约束文件在XML文件中的引用和使用:
student.xml
1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!-- 3 1.填写xml文档的根元素 4 2.引入xsi前缀. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 5 3.引入xsd文件命名空间. xsi:schemaLocation="http://www.itcast.cn/xml student.xsd" 6 4.为每一个xsd约束声明一个前缀,作为标识 xmlns="http://www.itcast.cn/xml" 7 8 9 --> 10 <students xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 11 xmlns="http://www.itcast.cn/xml" 12 xsi:schemaLocation="http://www.itcast.cn/xml student.xsd" 13 > 14 <student number="heima_0001"> 15 <name>tom</name> 16 <age>18</age> 17 <sex>male</sex> 18 </student> 19 20 </students>
标签:程序 value use val 指令 amp 图片 ace 编码方式
原文地址:https://www.cnblogs.com/fangtingfei/p/11404031.html