xml

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>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值