当前位置: 首页 > 图文教程 > XML家族 > XML Schema > 如何定义属性
加入实例文档的元素包含属性,怎么办呢?
customer2.xml
---------------
<customer id="001718">
<name>Teiki</name>
<address>No.237, Road Waitan, Shanghai</address>
</customer>
那就这样写Schema文档:
customer2.xsd
------------------
1: <?xml version="1.0"?>
2: <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
3:
4: <xsd:element name="customer">
5: <xsd:complexType>
6: <xsd:sequence>
7: <xsd:element name="name" type="xsd:string"/>
8: <xsd:element name="address" type="xsd:string" />
9: </xsd:sequence>
10: <!-- 增加属性定义 -->
11: <xsd:attribute name="id" type="xsd:string"/>
12: </xsd:complexType>
13: </xsd:element>
14:
15: </xsd:schema>
很简单,在<sequence>元素定义完成后,再用<attribute>元素id。
评论 (0) All