我正在使用 JAXB 生成 OpenOffice XML,并且需要应用 xml:space="preserve"
属性为 t
元素。
<r>
<t>
foo
</t>
</r>
应该是
<r>
<t xml:space="preserve">
foo
</t>
</r>
我使用 JAXB 从 Open Office 模式生成 Java 类。 <t>
type 在 CTRElt Java 类中表示为 String,因此无法设置此属性。当我从现有文档解码并编码时,以前存在 space
属性不再存在。
架构的相关部分如下:
<xsd:element name="t" type="ST_Xstring" minOccurs="1" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>Text</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:simpleType name="ST_Xstring">
<xsd:annotation>
<xsd:documentation>Escaped String</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:string" />
</xsd:simpleType>
如何生成具有此要求的 XML space
属性?修改模式不是一种选择。我需要自定义 JAXB 吗?
最佳答案
我最终生成了 XML 并使用正则表达式添加了属性 :(
关于java - 生成具有模式中不存在的属性的 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12100764/