jaxb - 为 xjc 优化外部绑定 XML
问题描述
您好我正在尝试为 xjc 创建一个外部绑定 XML,但出现 2 个错误:
[ERROR] A class/interface with the same name "x.x.DaysOfWeek" is already in use. Use a class customization to resolve this conflict.
[ERROR] (Relevant to above error) another "DaysOfWeek" is generated from here.
我错过了什么重要的东西吗?我需要第二双眼睛。谢谢
<!-- data.xsd -->
<xs:complexType name="DaysOfWeek">
<xs:sequence>
<xs:element ref="DaysOfWeek"/>
</xs:sequence>
</xs:complexType>
<xs:element name="DaysOfWeek">
<xs:complexType mixed="true">
<xs:attribute name="Type" use="required" type="xs:NCName"/>
</xs:complexType>
</xs:element>
我现在有 bindings.xml
<jaxb:bindings version="1.0" 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"
jaxb:extensionBindingPrefixes="xjc">
<jaxb:bindings schemaLocation="data.xsd">
<jaxb:schemaBindings>
<jaxb:package name="net.opengis.kml.v_2_2_0"/>
</jaxb:schemaBindings>
<jaxb:bindings node="xs:complexType[@name='DaysOfWeek']//xs:element[@ref='DaysOfWeek']">
<jaxb:property name="ComplexDaysOfWeek"/>
</jaxb:bindings>
<jaxb:bindings node="xs:element[@name='DaysOfWeek']">
<jaxb:factoryMethod name="ComplexDaysOfWeek"/>
</jaxb:bindings>
</jaxb:bindings>
解决方案
您对生成的类有冲突。尝试添加:
<jaxb:bindings node="xs:element[@name='DaysOfWeek']//xs:complexType">
<jaxb:class name="ComplexDaysOfWeekType"/>
</jaxb:bindings>
(也许没有//xs:complexType
,不太确定。)
推荐阅读
- java - 一旦我们在存储库的其他地方更新现有对象,它如何检索它的更改?
- python - 使用 pandas 和 python 得到“无法将字符串转换为浮点数”错误?
- node.js - socket.io 在 nodejs 中捕获任何事件
- f# - F#尝试添加(+)时“此值不是函数,无法应用”
- sql - 从多个表SQL中删除LEFT JOIN的结果
- angular - 在Angular中单击外部时如何关闭下拉列表?
- apache-flink - 如何动态设置源路径以从flink中的不同文件夹读取文件?
- itext7 - iText 7 - PdfReader 构造函数中的解析异常意外关闭输入流
- mysql - 包含两个反斜杠的 MySQL 文本
- solidity - 如何从 ethersjs 获取交易的状态消息