我有这样的 XML:
<?xml version="1.0" encoding="utf-8"?>
<Records xmlns="...">
<Some>
...
<Records>
<Record>
</Record>
</Records>
</Some>
</Records>
我生成 XDS,然后生成类:
xjc some.xsd
所以,我有以下结构:
如何解决这个问题?
最佳答案
您可以使用外部绑定(bind)文件来重命名从复杂类型生成的类。下面是一个示例,其中与复杂类型 itemType
对应的类将生成为 Item
。
<jxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
version="2.1">
<jxb:bindings schemaLocation="your-schema.xsd">
<jxb:bindings node="//xs:complexType[@name='itemType']">
<jxb:class name="Item"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
您可以使用 -b
标志在 XJC 调用中指定绑定(bind)文件
xjc -b binding.xml your-schema.xsd
关于xml - xjc 生成的重复嵌套类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16855552/