xml的简单使用
1、转义字符:<![CDATA[<朱之文]]>
2、xml约束: dtd 约束 (dtd后缀) 和 schema 约束 (xsd后缀)
dtd 约束:
<?xml version="1.0" encoding="UTF-8"?> <!ELEMENT students (student*)> <!ELEMENT student (name,password,gender,birthday)> <!ELEMENT name (#PCDATA)> <!ELEMENT password (#PCDATA)> <!ELEMENT gender (#PCDATA)> <!ELEMENT birthday (#PCDATA)> <!ATTLIST student number ID #REQUIRED>
students.xml
<?xml version="1.0" encoding="UTF-8"?> <students xmlns="http://www.gyf.cn/xml" xsi:schemaLocation="http://www.gyf.cn/xml students.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <student number="itgyf_1001"> <name>张三</name> <password>1234</password> <gender>female</gender> <birthday>2010-23-1</birthday> </student> <student number="itgyf_1002"> <name>李四</name> <password>1234</password> <gender>female</gender> <birthday>2010-23-1</birthday> </student> </students>
schema 约束 (xsd后缀):
<?xml version="1.0"?> <xsd:schema xmlns="http://www.gyf.cn/xml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.gyf.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="password" type="xsd:string" /> <xsd:element name="gender" type="genderType" /> <xsd:element name="birthday" type="xsd:string" /> </xsd:sequence> <xsd:attribute name="number" type="numberType" use="required"/> </xsd:complexType> <xsd:simpleType name="genderType"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="male"/> <xsd:enumeration value="female"/> </xsd:restriction> </xsd:simpleType> <xsd:simpleType name="numberType"> <xsd:restriction base="xsd:string"> <xsd:pattern value="itgyf_\d{4}"/> </xsd:restriction> </xsd:simpleType> </xsd:schema>

浙公网安备 33010602011771号