我无法弄清楚如何创建我的XSD文件来为子元素赋予唯一的ID。它对根元素工作正常,但复制这些代码并更改值不起作用,所以我认为我做错了什么。下面是我的XML:如何将唯一的ID添加到XSD文件中的子元素?
<?xml version="1.0" encoding="UTF-8"?>
<flights
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd">
<flight flightid="1">
<plane planeid="1">Airbus A380-861</plane>
</flight>
</flights>
下面是XSD文件:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="flights">
<xs:complexType>
<xs:sequence>
<xs:element name="flight"
type="flighttype"
minOccurs='1'
maxOccurs='unbounded' />
</xs:sequence>
</xs:complexType>
<xs:unique name="flightidisunique">
<xs:selector xpath="flight"/>
<xs:field xpath="@flightid"/>
</xs:unique>
</xs:element>
<xs:complexType name="flighttype">
<xs:sequence>
<xs:element name="plane"
type="planetype"
minOccurs='1'
maxOccurs='unbounded' />
</xs:sequence>
<xs:unique name="planeidisunique">
<xs:selector xpath="plane"/>
<xs:field xpath="@planeid"/>
</xs:unique>
<xs:attribute name="flightid" type="xs:string"/>
</xs:complexType>
<xs:complexType name="planetype">
<xs:sequence>
</xs:sequence>
<xs:attribute name="planeid" type="xs:string"/>
</xs:complexType>
</xs:schema>
什么是创造我已经发布了XML的有效模式的正确方法是什么?
这真是太神奇了,这完全是我在找的东西!我还需要知道使飞机在全球独一无二,或者只是在飞机内部的区别!非常感谢! – deucalion0 2013-02-12 08:57:40