【问题标题】:XPath for complexType wrapper in element元素中 complexType 包装器的 XPath
【发布时间】:2014-06-25 07:44:57
【问题描述】:

我在 XSD 架构中定义了以下元素

<xs:element name="MainType">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="InnerType">
        <xs:complexType>
          <xs:sequence>
            <xs:element ref="OtherType" maxOccurs="unbounded"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element>

我想为 OtherType 编写绑定,但是我遇到了 XPath 的问题。我写了这个 XPath 来寻址 OtherType。

//xs:element[@name='MainType']//xs:complexType//xs:element[@name='InnerType']//xs:complexType//xs:element[@name='OtherType']

我尝试在 XPath 中的元素之间跳过 complexType,但它也不起作用。 JAXB 插件返回此错误

om.sun.istack.SAXParseException2: XPath evaluation of ... results in empty target node

【问题讨论】:

  • 您要查找的最里面的属性是@ref='OtherType' 而不是@name?
  • 谢谢,我没有注意到这个错误。
  • 这是否回答了问题,即我们可以作为一个小错字关闭吗?
  • Als 重新考虑使用//
  • 整个 XPath 表达式对我来说似乎过于具体了。 //xs:element[@ref='OtherType'] 是否足够或者它真的必须是“xs:element[@ref='OtherType'],仅当xs:element[@name='InnerType] 的后代,仅当xs:element[@name='MainType'] 的后代,仅当任何节点的后代在文档中”?

标签: java xml xpath jaxb


【解决方案1】:

正确的 XPath:

//xs:element[@name='MainType']//xs:element[@name='InnerType//xs:element[@ref='OtherType']

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-02
    • 2012-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多