【发布时间】:2020-08-30 16:36:56
【问题描述】:
当在 XSD 中将 complexType 标记为 mixed="true" 时,生成的 Java 类会生成一个 List,其中包含“String”类型或围绕实际值的 JAXBElement 包装器。如果没有 mixed="true",则不会生成 JAXBElement,并且值会直接映射到类型类。例如:
<xs:complexType name="div" mixed="true">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="a" minOccurs="0" maxOccurs="unbounded" type="anchorType"/>
</xs:sequence>
...
</complexType>
这里的 div 类型将包含一个 List getContent() 方法,该方法返回一个字符串或 AnchorType 的 JAXBElement。
我希望它只返回没有 JAXBElement 的 String 或 AnchorType。
【问题讨论】:
-
为什么不直接从 'div' 的类型定义中删除 'mixed=true' 呢?
-
我需要能够放入纯文本和元素 - 类似于 HTML div 元素
标签: java xsd jaxb jaxb2-maven-plugin jaxb2-basics