【发布时间】:2014-02-17 15:22:40
【问题描述】:
我正在尝试通过 columns id 属性创建一个具有行引用列的架构。以下 xml 和 xsd 将无法验证,因为找不到该列
如何为以下 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>
【问题讨论】:
-
你能展示你目前写的架构吗?
-
我把它添加到原来的问题中