[英]How to rename xs:simpleType during jaxb XJC generation?
I'm using jaxb
and xjc
to autogenerate java classes from xsd
files.我正在使用
jaxb
和xjc
从xsd
文件自动生成 java 类。
Problem: I have two files that show the same simpleType
name.问题:我有两个文件显示相同的
simpleType
名称。 And thus get a compilation error:从而得到一个编译错误:
xsd1.xsd [49:3]: 'FileKey' is already defined
xsd1: xsd1:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:simpleType name="FileKey">
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z0-9_]+" />
</xs:restriction>
</xs:simpleType>
...
</xs:schema>
xsd2: xsd2:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:simpleType name="FileKey">
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z0-9_]+" />
</xs:restriction>
</xs:simpleType>
...
</xs:schema>
My binding file that I tried:我试过的绑定文件:
<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"
jaxb:version="2.1">
<jaxb:bindings schemaLocation="xsd1.xsd">
<jaxb:bindings node="//xs:simpleType[@name='FileKey']">
<jaxb:class name="FileKeyRenamed" />
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
Sidenote: I cannot modify the xsds, as I have no conrol of them.旁注:我无法修改 xsds,因为我无法控制它们。
Try using typeSafeEnumClass annotation:尝试使用 typeSafeEnumClass 注释:
<jaxb:bindings schemaLocation="xsd1.xsd">
<jaxb:bindings node="//xs:simpleType[@name='FileKey']" >
<jaxb:typesafeEnumClass name="FileKeyRenamed" />
</jaxb:bindings>
</jaxb:bindings>
See more here: https://coderleaf.wordpress.com/2016/11/15/jaxb-bindings-by-example/ .在此处查看更多信息: https://coderleaf.wordpress.com/2016/11/15/jaxb-bindings-by-example/ 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.