【问题标题】:specifying a JAXB external binding for XSD sequence nodeName and choice/sequence nodeName为 XSD 序列节点名和选择/序列节点名指定 JAXB 外部绑定
【发布时间】:2018-05-02 16:54:38
【问题描述】:

我正在尝试使用我不维护的 xsd 上的 jxb 外部绑定来消除“元素“___”出现在多个属性中”。

我可以使用以下方法修改 XSD:

    <xs:complexType name="credit">
    <xs:sequence>
        <xs:element .../>
        <xs:element name="link" type="link" minOccurs="0" maxOccurs="unbounded">
            <xs:annotation> <xs:appinfo> <jxb:property name="linkElement"/> </xs:appinfo> </xs:annotation> 
        </xs:element>
        <xs:choice>
            <xs:sequence>
                ...
                <xs:sequence minOccurs="0" maxOccurs="unbounded">
                    <xs:element name="link" type="link" minOccurs="0" maxOccurs="unbounded"/>
                    ...
                </xs:sequence>
            </xs:sequence>
        </xs:choice>
    </xs:sequence>
    ...

创建Link类型的序列linkElement和选择序列:

    @XmlElement(name = "link")
protected List<Link> linkElement;
...
@XmlElements({
    @XmlElement(name = "link", type = Link.class),
    ...
})
protected List<Object> linkAndBookmarkAndCreditWords;

但是当我尝试使用 JAXB 外部绑定文件时:

<jxb:bindings node="//xs:complexType[@name='credit']//xs:sequence//xs:element[@name='link']" >
        <jxb:property name="linkElement" />
    </jxb:bindings>

我得到错误:

[ERROR] XPath evaluation of "...[@name='link']" results in too many (2) target nodes

我如何才能像在内部绑定中那样只区分第一个“链接”节点?

【问题讨论】:

    标签: jaxb


    【解决方案1】:

    您的 XPath 表达式不够精确。这些// 的意思是“低于当前节点的任何地方”。这包括您的两个 link 元素。

    尝试使您的 XPath 表达式更精确,类似于以下内容:

    xs:complexType[@name='credit']/xs:sequence/xs:element[@name='link']
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-30
      • 2014-10-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多