英文:
Error when generating JAVA classes with JAXB: XPath evaluation of results in empty
问题
我有一个XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.xyz.m" xmlns="http://www.xyz.m" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="N1" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="N_A">
<xs:simpleType>
<xs:restriction base="xs:byte">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="3"/>
<xs:totalDigits value="2"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="N_B" minOccurs="1" maxOccurs="14">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="5"/>
<xs:enumeration value="6"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
我创建了一个.xjb
文件以生成:
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
version="2.1">
<jaxb:bindings node="//xs:schema//xs:complexType[@name='N1']">
<jaxb:class name="N1_XJB" />
</jaxb:bindings>
</jaxb:bindings>
我使用了xjc -b binding.xjb TestXSD.xsd
命令,但是我收到了以下错误消息:
[ERROR] XPath evaluation of "//xs:schema//xs:complexType[@name='N1']" results in empty target node line 6
我尝试了在Stackoverflow上找到的所有方法,但我无法生成。
所以我的问题是,.xjb
文件缺少了什么部分?
英文:
I have an XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.xyz.m" xmlns="http://www.xyz.m" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="N1" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="N_A">
<xs:simpleType>
<xs:restriction base="xs:byte">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="3"/>
<xs:totalDigits value="2">
</xs:totalDigits>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="N_B" minOccurs="1" maxOccurs="14">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="5"/>
<xs:enumeration value="6"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
I created an .xjb
file to generate:
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
version="2.1">
<jaxb:bindings node="//xs:schema//xs:complexType[@name='N1']">
<jaxb:class name="N1_XJB" />
</jaxb:bindings>
</jaxb:bindings>
I used xjc -b binding.xjb TestXSD.xsd
command, but I got this ERROR message:
[ERROR] XPath evaluation of "//xs:schema//xs:complexType[@name='N1']" results in empty target node line 6
I tried every method I found on Stackoverflow, but I can't generate.
So my question is, what are missing from .xjb
file?
答案1
得分: 1
这对我有效:
- 您必须从
<xs:element name="N1" minOccurs="0">
中删除minOccurs
。因为该属性会生成以下错误:
[ERROR] s4s-att-not-allowed: 属性'minOccurs'不能出现在元素'element'中。
- 在
.xjb
文件中,您必须将以下行从:
<jaxb:bindings node="//xs:schema//xs:complexType[@name='N1']">
更改为:
<jaxb:bindings schemaLocation="TestXSD.xsd" node="//xs:schema//xs:element[@name='N1']">
英文:
This work for me:
- You must delete
minOccurs
from<xs:element name="N1" minOccurs="0">
. Because this attribute generates the following error:
[ERROR] s4s-att-not-allowed: Attribute 'minOccurs' cannot appear in element 'element'.
- In the
.xjb
file, you must change the following line from:
<jaxb:bindings node="//xs:schema//xs:complexType[@name='N1']">
to:
<jaxb:bindings schemaLocation="TestXSD.xsd" node="//xs:schema//xs:element[@name='N1']">
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论