使用模式中没有的属性生成XML

时间:2022-07-23 17:17:11

I'm generating OpenOffice XML using JAXB, and need to apply an xml:space="preserve" attribute to a t element.

我使用JAXB生成OpenOffice XML,并需要应用XML:space=“保存”属性到t元素。

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

Should be

应该是

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

I've used JAXB to generate Java classes from Open Office schemas. <t> type is represented as a String in the CTRElt Java class, so there is no way to set this attribute. When I unmarshall from an existing document and marshall, previously existing space attributes are no longer present.

我使用JAXB从开放的办公模式生成Java类。 类型在CTRElt Java类中表示为一个字符串,因此无法设置该属性。当我从一个现有的文档和marshall中找到marshall时,先前存在的空间属性不再存在。

The relevant portions of the schema are as follows:

模式的相关部分如下:

<xsd:element name="t" type="ST_Xstring" minOccurs="1" maxOccurs="1"> <xsd:annotation> <xsd:documentation>Text</xsd:documentation> </xsd:annotation> </xsd:element>

Text 元素名称="t">

<xsd:simpleType name="ST_Xstring"> <xsd:annotation> <xsd:documentation>Escaped String</xsd:documentation> </xsd:annotation> <xsd:restriction base="xsd:string" /> </xsd:simpleType>

simpleType名称="ST_Xstring"> 注释>

How can I generate XML which has this required space attribute? Modifying the schema is not an option. Do I need to customize JAXB?

如何生成具有所需空间属性的XML ?修改模式不是一个选项。需要自定义JAXB吗?

1 个解决方案

#1


0  

I ended up generating the XML and using a regex to add the attribute :(

最后生成了XML,并使用regex添加属性:(

#1


0  

I ended up generating the XML and using a regex to add the attribute :(

最后生成了XML,并使用regex添加属性:(