HyperJAXB3 - 解析XSD,包括xs:任何通配符

时间:2018-05-23 07:17:28

标签: xml jpa xsd jaxb hyperjaxb

我有一个巨大的xsd架构(开源railsML 2.2格式),我正在尝试创建一个JPA带注释的对象模型。我想使用HyperJAXB3。

XSD架构包含一些<xs:any namespace="##other" />元素。我没有机会更改xsd文件。 hyperjaxb编译器给出错误:

Class [org.railml.schemas._2013.TElementWithIDAndName] declares an attribute wildcard. This is currently not supported. See issue #46.

所以Hyperjaxb似乎对这些通配符构造有问题。我尝试添加hj:ignored绑定

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    xmlns:hj="http://hyperjaxb3.jvnet.org/ejb/schemas/customizations"
    version="2.1">
    <!-- global bindings -->
    <jaxb:globalBindings>
        <xjc:simple />
    </jaxb:globalBindings>

    <jaxb:bindings
        schemaLocation="genericRailML.xsd">

        <jaxb:bindings node="//xs:schema//xs:complexType[@name='tElementWithIDAndName']//xs:sequence//xs:any">
            <hj:ignored/>
        </jaxb:bindings>
    </jaxb:bindings>    
</jaxb:bindings>

然后编译器给出:

[ERROR] compiler was unable to honor ignored customization. It is attached to a wrong place, or its inconsistent with other bindings.

引用的XSD部分:

<xs:schema xmlns:rail="http://www.railml.org/schemas/2013" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:dc="http://purl.org/dc/elements/1.1/" targetNamespace="http://www.railml.org/schemas/2013" elementFormDefault="qualified" version="2.2">

...

  <xs:complexType name="tElementWithIDAndName">
    <xs:annotation>
      <xs:documentation>generic base type, used for inheritance of many railML types</xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="additionalName" type="rail:tAdditionalName" minOccurs="0" maxOccurs="unbounded">
        <xs:annotation>
          ...
        </xs:annotation>
      </xs:element>
      <xs:any namespace="##other" processContents="strict" minOccurs="0" maxOccurs="unbounded">
        <xs:annotation>
          <xs:documentation>provide an extension point for non-railML elements in foreign namespace</xs:documentation>
        </xs:annotation>
      </xs:any>
    </xs:sequence>
    <xs:attribute name="id" type="rail:tGenericID" use="required">
      ...
    </xs:attribute>
    ...
  </xs:complexType>

...
</xs:schema>

有没有办法用HyperJAXB解析XSD文档,还是有办法绕过xs:any元素?

0 个答案:

没有答案
相关问题