编辑:添加键.
嗨,
我有一个xml架构,其中包含以下类型:
@H_301_15@<xs:complexType name="definition"> <xs:sequence/> <xs:attribute name="id"/> </xs:complexType> <xsd:key name="definitionId"> <xsd:selector xpath="definition"/> <xsd:field xpath="@id"/> </xsd:key> <xs:complexType name="elem"> <xs:sequence> <xs:element name="entry1" type="elem" minOccurs="0" maxOccurs="unbounded"/> <xs:element name="entry2" type="xs:string" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> <xs:attribute name="ref" type="xs:string" use="required"/> </xs:complexType>这允许类似于:
@H_301_15@<definition id="A"> <definition id="B"> <definition id="C"> <entry1 ref="A"> <entry1 ref="B"> <entry1 ref="C"/> <entry2/> </entry1> <entry1 ref="C"> </entry1> </entry1>我需要一个XPath选择器来声明ref属性的keyref,但我不知道如何定义递归路径.
@H_301_15@<xsd:keyref name="definitionRef" refer="definitionId"> <xsd:selector xpath="???"/> <<<how to find all "ref" of entry1 ? <xsd:field xpath="@ref"/> </xsd:keyref>谢谢你的时间.
解决方法
< XSD:选择>支持受限制的XPath表达式.只允许使用子轴,但XPath表达式可以以.//开头,因此您可以使用递归表达式.//entry1
有关更多详细信息,请参阅规范:http://www.w3.org/TR/xmlschema-1/#c-selector-xpath
< xsd:selector> element包含一个XML Path Language(XPath)表达式,用于指定由field指定的值必须唯一的元素集,因此它不应引用属性ref. < XSD:字段> element(s)引用在该集合中应该唯一的值,因此它应该引用属性ref(如果需要具有唯一的值组合,则应将其余字段引用到其他值).