我正在嘗試通過列id屬性創建具有行引用列的模式。下面的XML和XSD將不會驗證因爲該列無法找到在XML模式中使用ref
如何創建以下XML架構,這樣我可以從行元素引用的列ID:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<rows>
<row>
<column id="123" />
<column id="124" />
</row>
<row>
<column id="123" />
<column id="124" />
</row>
</rows>
<columns>
<column id="123">
<name>Apple</name>
</column>
<column id="124">
<name>Banana</name>
</column>
</columns>
</mapping>
我的XSD看起來像這一點,但它不工作...它無法找到列引用:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="mapping">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="rows" type="Rows" minOccurs="0" maxOccurs="1"/>
<xsd:element name="columns" type="Columns" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
<xsd:key name="PKeyColumn">
<xsd:selector xpath="columns/column"/>
<xsd:field xpath="@id"/>
</xsd:key>
<xsd:keyref name="FKeyColumn" refer="PKeyColumn">
<xsd:selector xpath="rows/row/column"/>
<xsd:field xpath="@id"/>
</xsd:keyref>
</xsd:element>
<xsd:complexType name="Row">
<xsd:sequence>
<xsd:element ref="column">
<xsd:complexType>
<xsd:attribute name="id" use="required" type="xsd:integer" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Rows">
<xsd:sequence>
<xsd:element name="row" type="Row" minOccurs="1" maxOccurs="unbounded">
<xsd:unique name="UKeyColumn">
<xsd:selector xpath="column"/>
<xsd:field xpath="@id"/>
</xsd:unique>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Columns">
<xsd:sequence>
<xsd:element name="column" type="Column" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Column">
<xsd:sequence>
<xsd:element name="name" type="xsd:string" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:integer" />
</xsd:complexType>
</xsd:schema>
您可以顯示迄今爲止寫入的模式嗎? –
我將它添加到原始問題 – user3319681