xml内部定义实体
编写一个courses.xml使用自定也实体,company代表昆山杰普软件科技有限公司
cources里有name,teacher,time,test标签元素,name、time为字符型,teache为任意类型,
test中只能包含a、b两字标签
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE courses[
<!ELEMENT courses (name,teacher,time,test)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT teacher ANY>
<!ELEMENT time (#PCDATA)>
<!ELEMENT test (a*,b*)>
<!ENTITY bj "昆山杰普软件科技有限公司">
]>
<courses>
<name>&bj;</name>
<teacher>company</teacher>
<time>'10:00'</time>
<test>
<a></a>
<b></b>
</test>
</courses>
编写一个employee.xml
其中保留员工的id,name,age,depName,salary,company,gender信息.
要求 company使用自定义实体实现
id必须有并且不能相同
name任意
age可以不出现,不出现时有默认值20
depName只能在(市场部,教学部,教学管理部)中产生
salary可以不出现,一旦出现必须有值
gender可以不出现,不出现是有默认值male
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE employees[
<!ENTITY company "briup">
<!ELEMENT employees (employee+)>
<!ELEMENT employee (id,name,age,depName,salary,gender)>
<!ATTLIST employee
id ID #REQUIRED
name CDATA #IMPLIED
age CDATA "20"
depName (市场部|教学部|教学管理部) #REQUIRED
salary CDATA #FIXED "100"
gender CDATA "male"
>
<!ELEMENT id (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT age (#PCDATA)>
<!ELEMENT depName (#PCDATA)>
<!ELEMENT salary (#PCDATA)>
<!ELEMENT gender (#PCDATA)>
]>
<employees>
<employee id="a1"
name="zhangsan"
age="20"
depName="市场部"
salary="100"
gender="male"
>
<id></id>
<name></name>
<age></age>
<depName></depName>
<salary></salary>
<gender></gender>
</employee>
</employees>
编写一个customer.xml
要求:根元素customers,customers中只包含6个customer元素,
customer中只有属性name(取值tom,alexlee,jack),必须出现
customer内容是double类型的消费数目.
对customer.xml文件的内容进行限制的customer.xsd文件内容如下:
<?xml version="1.0" encoding="UTF-8" ?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/customer"
xmlns:tns="http://www.example.org/customer">
<element name="customers" type="tns:customersType"></element>
<complexType name="customersType">
<sequence>
<element name="customer" type="tns:customerType" minOccurs="1" maxOccurs="6"></element>
</sequence>
</complexType>
<complexType name="customerType">
<simpleContent>
<extension base="double">
<attribute name="name">
<simpleType>
<restriction base="string">
<enumeration value="tom"/>
<enumeration value="jack"/>
<enumeration value="luck"/>
</restriction>
</simpleType>
</attribute>
</extension>
</simpleContent>
</complexType>
</schema>
customer.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<tns:customers xmlns:tns="http://www.example.org/customer"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/customer customer.xsd ">
<customer name="tom">2222</customer>
<customer name="jack">2000</customer>
<customer name="luck">2000</customer>
<customer name="tom">2000</customer>
<customer name="luck">2000</customer>
<customer name="luck">2000</customer>
</tns:customers>