【问题标题】:Generate XML with attribute which is absent from the schema使用模式中不存在的属性生成 XML
【发布时间】:2012-08-19 12:11:44
【问题描述】:

我正在使用 JAXB 生成 OpenOffice XML,并且需要将 xml:space="preserve" 属性应用于 t 元素。

    <r>
        <t>
            foo
        </t>
    </r>

应该是

    <r>
        <t xml:space="preserve">
            foo
        </t>
    </r>

我使用 JAXB 从 Open Office 模式生成 Java 类。 &lt;t&gt; 类型在 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>

如何生成具有此必需 space 属性的 XML?修改架构不是一种选择。我需要自定义 JAXB 吗?

【问题讨论】:

标签: java xml jaxb


【解决方案1】:

我最终生成了 XML 并使用正则表达式添加属性:(

【讨论】:

    猜你喜欢
    • 2023-03-17
    • 2012-05-23
    • 1970-01-01
    • 2021-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-10
    相关资源
    最近更新 更多