如何使用 xpath 获取特定的 xsd 元素?
How to use xpath to get a specific xsd element?
我正在尝试查找特定父 xsd 元素的特定 xsd 元素
使用 xpath 但找不到解决方案。
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="XYZ">
<xs:complexType>
<xs:sequence>
<xs:element name="XX" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="AA">
<xs:complexType>
<xs:attribute type="xs:string" name="testA" use="required" />
<xs:attribute type="xs:string" name="testB" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="YY" minOccurs="0" />
<xs:element name="ZZ">
<xs:complexType>
<xs:sequence>
<xs:element name="AA" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
我尝试了以下 xpath:
/xs:element[@name='XYZ']/xs:element[@name='XX']/xs:element[@name='AA']
但结果是一个空列表。
我希望有人能帮助我。
//xs:element[@name="XYZ"]//xs:element[@name="XX"]//xs:element[@name="AA"]
应该会给出想要的结果 - 您只需要使用 //
来处理任意深度的祖先。
bookstore//title
所有 <title>
元素在 <bookstore>
元素(任意后代)中深入一层或多层。
bookstore//book/excerpt//emph
所有 <emph>
元素在 <book>
元素的 <excerpt>
子元素内的任何位置,在 <bookstore>
元素内的任何位置。
我正在尝试查找特定父 xsd 元素的特定 xsd 元素 使用 xpath 但找不到解决方案。
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="XYZ">
<xs:complexType>
<xs:sequence>
<xs:element name="XX" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="AA">
<xs:complexType>
<xs:attribute type="xs:string" name="testA" use="required" />
<xs:attribute type="xs:string" name="testB" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="YY" minOccurs="0" />
<xs:element name="ZZ">
<xs:complexType>
<xs:sequence>
<xs:element name="AA" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
我尝试了以下 xpath:
/xs:element[@name='XYZ']/xs:element[@name='XX']/xs:element[@name='AA']
但结果是一个空列表。
我希望有人能帮助我。
//xs:element[@name="XYZ"]//xs:element[@name="XX"]//xs:element[@name="AA"]
应该会给出想要的结果 - 您只需要使用 //
来处理任意深度的祖先。
bookstore//title
所有 <title>
元素在 <bookstore>
元素(任意后代)中深入一层或多层。
bookstore//book/excerpt//emph
所有 <emph>
元素在 <book>
元素的 <excerpt>
子元素内的任何位置,在 <bookstore>
元素内的任何位置。