我正在尝试让 hyperjaxb 处理真实的模式。我下载并解压了hyperjaxb maven项目from this link然后使用 cmd.exe
导航到根目录,并通过运行 mvn clean install
使用示例数据对其进行测试,以确保它适用于示例架构。然后,我用实际示意图的精简版本替换了 schema.xsd
、po.xml
和 bindings.xjb
文件,以便我可以准备通过上面链接的 hyperjaxb 项目运行真正的应用程序。然后我再次运行mvn clean install
。但是,我收到以下错误消息:
[ERROR] Error while parsing schema(s).Location
[ file:/C:/path/to/src/main/resources/bindings.xjb{25,53}].
com.sun.istack.SAXParseException2; systemId:
file:/C:/path/to/src/main/resources/bindings.xjb; lineNumber: 25; columnNumber: 53;
XPath evaluation of "xs:complexType[@name='Any']" results in empty target node
从您可以读取的替换 bindings.xjb
文件 at this link.
使用 schema.xsd
文件 at this link ,以及您可以读取的 po.xml
at this link 。
bindings.xjb 的相关部分是:
<jaxb:bindings node="xs:complexType[@name='Any']">
<hj:entity>
<orm:table name="any"/>
</hj:entity>
</jaxb:bindings>
schema.xsd 中 ANY
复杂类型的定义是:
<xs:complexType name="ANY"><!-- abstract="true">-->
<xs:annotation>
<xs:documentation>
Some documentation.
</xs:documentation>
</xs:annotation>
<xs:attribute name="nullFlavor" type="NullFlavor" use="optional">
<xs:annotation>
<xs:documentation>
Some other documentation.
</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
请注意,完整的代码位于上面的链接中。 如何解决此错误?
最佳答案
您应该使用以下配置..
<jaxb:bindings node="//xs:complexType[@name='ANY']">
<hj:entity>
<orm:table name="any"/>
</hj:entity>
</jaxb:bindings>
您可以在此处找到我对另一个主题的回答的示例。 https://stackoverflow.com/a/24953369/3364187
我尝试了你的项目,这个配置工作正常。让我知道是否适用于您的环境。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
version="2.1"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:hj="http://hyperjaxb3.jvnet.org/ejb/schemas/customizations"
xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
jaxb:extensionBindingPrefixes="hj orm">
<jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema">
<jaxb:globalBindings generateIsSetMethod="true"/>
<jaxb:schemaBindings>
<jaxb:package name="org.jvnet.hyperjaxb3.ejb.tests.pocustomized"/>
</jaxb:schemaBindings>
<jaxb:bindings node="//xs:complexType[@name='InfrastructureRoot.typeId']">
<hj:entity>
<orm:table name="typeId"/>
</hj:entity>
</jaxb:bindings>
<jaxb:bindings node="//xs:complexType[@name='II']">
<hj:entity>
<orm:table name="II"/>
</hj:entity>
</jaxb:bindings>
<jaxb:bindings node="//xs:complexType[@name='ANY']">
<hj:entity>
<orm:table name="any"/>
</hj:entity>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
简而言之,每个节点都丢失//
Selects nodes in the document from the current node that match the selection no matter where they are
并且复杂类型不是“Any”而是“ANY”,那么正确的节点是@name='ANY'
关于xml - "xs:complexType[@name=' Any']"的 XPath 评估导致目标节点为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26410154/