xml - HyperJAXB3 - 解析 XSD,包括 xs:any 通配符
问题描述
我有一个巨大的 xsd 模式(开源 railML 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
元素?
解决方案
推荐阅读
- java - 在 Array 中查找特定的 char 元素
- webdriver-io - 如何使用在 webdriverio 中进行回调的 3rd 方方法
- testing - Ng 测试 - 无法绑定到“值”,因为它不是“垫选择”的已知属性
- vue.js - 没有 webpack/npm/yarn 的 Vue 组件
- python - 将来自 Telegram 的传入消息转发到另一个聊天室
- python - 从 pandas DataFrame Columns 创建索引
- php - 无法获得本地颁发者证书 WordPress 2018 PHP 7.2 - cacert.pem 不起作用
- amazon-web-services - 哪些 CloudWatch 事件会触发 Glue 作业启动?
- angular - 值不会在 D3 条形图中使用动态反映。与现有图表发生重叠。
- android - 如何将光标带到 EditText 并在 AlertDialog 弹出窗口中自动调出键盘