我正在使用 xjc 从 XML 模式生成 Java 类,以下是 XSD 的摘录。
<xs:element name="NameInfo">
<xs:complexType>
<xs:sequence>
<xs:choice>
<xs:element ref="UnstructuredName"/> <!-- This line -->
<xs:sequence>
<xs:element ref="StructuredName"/>
<xs:element ref="UnstructuredName" minOccurs="0"/> <!-- and this line! -->
</xs:sequence>
</xs:choice>
<xs:element ref="SomethingElse" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
在大多数情况下,生成的类都很好,但对于上面的块,我会得到类似的东西:
public List<Object> getContent() {
if (content == null) {
content = new ArrayList<Object>();
}
return this.content;
}
上面有以下评论:
* You are getting this "catch-all" property because of the following reason:
* The field name "UnstructuredName" is used by two different parts of a schema. See:
* line XXXX of file:FILE.xsd
* line XXXX of file:FILE.xsd
* To get rid of this property, apply a property customization to one
* of both of the following declarations to change their names:
* Gets the value of the content property.
我在有问题的两行末尾发表了评论。
目前,我认为更改架构并不容易,因为这是由供应商决定的,我不想走这条路(如果可能的话),因为它会大大减慢进度。
我搜索了,找到了这个页面,外部定制是我想做的吗?我大部分时间都在使用生成的类,所以我并不完全熟悉生成这些类的过程。“属性定制”的简单示例会很棒!只要模式仍然可以使用,生成 Java 类的替代方法就可以了。
编辑:我应该澄清这两者UnstructuredName
确实是相同的元素。