Java JAXB:package.package<;类型>;是否已在包中定义。包。<;类型>&书信电报;类型>;
我试图用JAXB从XSD生成java类 XSD是我公司的官方XSD,因此我不能仅为我的项目修改它们。 在害怕尝试和搜索这个网站后,我决定直接问这个问题 我的XSD中有这个:Java JAXB:package.package<;类型>;是否已在包中定义。包。<;类型>&书信电报;类型>;,java,xml,xpath,xsd,jaxb,Java,Xml,Xpath,Xsd,Jaxb,我试图用JAXB从XSD生成java类 XSD是我公司的官方XSD,因此我不能仅为我的项目修改它们。 在害怕尝试和搜索这个网站后,我决定直接问这个问题 我的XSD中有这个: <xs:element name="Line" minOccurs="0" maxOccurs="999"> <xs:complexType>
<xs:element name="Line" minOccurs="0" maxOccurs="999">
<xs:complexType>
<xs:sequence>
<xs:element name="Line" minOccurs="0" maxOccurs="999">
<xs:complexType>
<xs:attribute name="reference" type="xs:toto" use="optional">
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="reference" type="xs:toto" use="optional">
</xs:attribute>
</xs:complexType>
</xs:element>
它导致了以下问题:
package.Index.Line已在package.Index中定义
在查看生成的代码后,我可以看到,我们有一个静态的类行,进入另一个静态的内部类行(在另一个索引下)
我在行中得到错误(在顶部和底部)
嵌套类型行不能隐藏封闭类型
如果名称发生了变化(在xsd上或在java类生成之后),我就不再有问题了
我试图创建一个绑定文件:
<jaxb:bindings schemaLocation="file:../path/myschema.xsd" node="//xs:element[@name='Index']">
<jaxb:bindings node=".//xs:element[@name='Line']" multiple="true">
<jaxb:property name="Lines"/>
</jaxb:bindings>
</jaxb:bindings>
我也有同样的问题。。。因为实际上在索引下,我有两个节点,所以我尝试这样做:
<jaxb:bindings schemaLocation="file:path/myxsd.xsd" node="//xs:element[@name='Index']/xs:element[@name='Line']">
<jaxb:bindings node="//xs:element[@name='Line']" multiple="true">
<jaxb:property name="Lines"/>
</jaxb:bindings>
</jaxb:bindings>
或
但我有一个世代问题:
com.sun.istack.SAXParseException2:对“//xs:element[@name='Index']]/xs:element[@name='Line']”的XPath求值将导致空目标节点
我完全迷路了。我整天都在吃坚果来补偿我的悲伤
如果你有建议;)
提前谢谢
Geoffrey首先配置绑定以将其生成为单个类
<jaxb:globalBindings localScoping="toplevel"/>
首先配置绑定以将其生成为单个类
<jaxb:globalBindings localScoping="toplevel"/>
行位于
xs:complexType
内。不在xs:element
line下那么您将如何做到这一点?这不起作用
请参见下面我的答案。行在xs:complexType
内。不在xs:element
line下那么您将如何做到这一点?这不起作用
请参见下面我的答案。
<bindings version="2.1" xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<globalBindings localScoping="toplevel"/>
<bindings schemaLocation="yourschema.xsd">
<bindings node="//xs:element[@name='Index']/xs:complexType/xs:sequence/xs:element[@name='Line']/xs:complexType">
<class name="Lines1"/>
</bindings>
</bindings>
<bindings schemaLocation="yourschema.xsd">
<bindings node="//xs:element[@name='Index']/xs:complexType/xs:sequence/xs:element[@name='Line']/xs:complexType/xs:sequence/xs:element[@name='Line']/xs:complexType">
<class name="Lines2"/>
</bindings>
</bindings>
</bindings>