生成使用JAXB的JAVA类时出错:XPath对导致为空的结果进行了评估

huangapple go评论82阅读模式
英文:

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:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;xs:schema targetNamespace=&quot;http://www.xyz.m&quot; xmlns=&quot;http://www.xyz.m&quot; xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; elementFormDefault=&quot;qualified&quot; attributeFormDefault=&quot;unqualified&quot;&gt;
&lt;xs:element name=&quot;N1&quot; minOccurs=&quot;0&quot;&gt;
	&lt;xs:complexType&gt;
		&lt;xs:sequence&gt;
			&lt;xs:element name=&quot;N_A&quot;&gt;
			&lt;xs:simpleType&gt;
				&lt;xs:restriction base=&quot;xs:byte&quot;&gt;
				&lt;xs:minInclusive value=&quot;0&quot;/&gt;
				&lt;xs:maxInclusive value=&quot;3&quot;/&gt;
				&lt;xs:totalDigits value=&quot;2&quot;&gt;
				&lt;/xs:totalDigits&gt;
			&lt;/xs:restriction&gt;
				&lt;/xs:simpleType&gt;
			&lt;/xs:element&gt;
		&lt;xs:element name=&quot;N_B&quot; minOccurs=&quot;1&quot; maxOccurs=&quot;14&quot;&gt;
			&lt;xs:simpleType&gt;
			&lt;xs:restriction base=&quot;xs:string&quot;&gt;
				&lt;xs:enumeration value=&quot;5&quot;/&gt;
				&lt;xs:enumeration value=&quot;6&quot;/&gt;
				&lt;/xs:restriction&gt;
			&lt;/xs:simpleType&gt;
		&lt;/xs:element&gt;
	&lt;/xs:sequence&gt;
	&lt;/xs:complexType&gt;
&lt;/xs:element&gt;
&lt;/xs:schema&gt;	

I created an .xjb file to generate:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;jaxb:bindings
    xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;
    xmlns:jaxb=&quot;http://java.sun.com/xml/ns/jaxb&quot;
    version=&quot;2.1&quot;&gt;
   &lt;jaxb:bindings node=&quot;//xs:schema//xs:complexType[@name=&#39;N1&#39;]&quot;&gt;
        &lt;jaxb:class name=&quot;N1_XJB&quot; /&gt;
    &lt;/jaxb:bindings&gt;	
&lt;/jaxb:bindings&gt;

I used xjc -b binding.xjb TestXSD.xsd command, but I got this ERROR message:

[ERROR] XPath evaluation of &quot;//xs:schema//xs:complexType[@name=&#39;N1&#39;]&quot; 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

这对我有效:

  1. 您必须从&lt;xs:element name=&quot;N1&quot; minOccurs=&quot;0&quot;&gt;中删除minOccurs。因为该属性会生成以下错误:

[ERROR] s4s-att-not-allowed: 属性'minOccurs'不能出现在元素'element'中。

  1. .xjb文件中,您必须将以下行从:

&lt;jaxb:bindings node=&quot;//xs:schema//xs:complexType[@name=&#39;N1&#39;]&quot;&gt;

更改为:

&lt;jaxb:bindings schemaLocation=&quot;TestXSD.xsd&quot; node=&quot;//xs:schema//xs:element[@name=&#39;N1&#39;]&quot;&gt;
英文:

This work for me:

  1. You must delete minOccurs from &lt;xs:element name=&quot;N1&quot; minOccurs=&quot;0&quot;&gt;. Because this attribute generates the following error:

[ERROR] s4s-att-not-allowed: Attribute &#39;minOccurs&#39; cannot appear in element &#39;element&#39;.

  1. In the .xjb file, you must change the following line from:

&lt;jaxb:bindings node=&quot;//xs:schema//xs:complexType[@name=&#39;N1&#39;]&quot;&gt;

to:

&lt;jaxb:bindings schemaLocation=&quot;TestXSD.xsd&quot; node=&quot;//xs:schema//xs:element[@name=&#39;N1&#39;]&quot;&gt;

huangapple
  • 本文由 发表于 2020年7月28日 20:59:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/63134726.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定