编程语言
首页 > 编程语言> > java – 绑定中的JAXB空节点

java – 绑定中的JAXB空节点

作者:互联网

JAXB无法解析此示例的绑定:

<xs:element name="classA" type="classA" substitutionGroup="classSubA"/>

<xs:complexType name="complexClassA" mixed="true">

<xs:attribute name="attA">
    <xs:annotation>
        <xs:appinfo>
            <moProperty value="classA:attA"/>
            <label value="Attribute A" default="true"/>
            <externAccess value="readWrite"/>
            <description value="NO COMMENTS"/>
        </xs:appinfo>
    </xs:annotation>
    <xs:simpleType>
        <xs:restriction base="xs:string">
            <xs:enumeration value="off"/>
            <xs:enumeration value="on"/>
        </xs:restriction>
    </xs:simpleType>
</xs:attribute>

而bindings.xml(片段):

<jxb:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" version="2.1">
    <jxb:bindings schemaLocation="schema/mySchema.xsd">
        <jxb:bindings node="//xs:complexType[@name='complexClassA']">
            <jxb:bindings node=".//xs:element[@name='attA']">
                <jxb:property name="att" />
            </jxb:bindings>
        </jxb:bindings>
    </jxb:bindings>
</jxb:bindings>

生成Java文件时,错误是:

com.sun.istack.SAXParseException2: XPath evaluation of ".//xs:element[@name='attA']" results in empty target node

我在俯瞰什么?

谢谢.

你做.

解决方法:

我认为这:

<jxb:bindings node=".//xs:element[@name='attA']">

应该是这样的:

<jxb:bindings node=".//xs:attribute[@name='attA']">

您有一个属性,XPath适用于一个元素.

标签:java,java-ee,xjc,jaxb2
来源: https://codeday.me/bug/20190710/1418896.html