2

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

    <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.

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>

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

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

Filburt
  • 17,626
  • 12
  • 64
  • 115
Sam Barnum
  • 10,559
  • 3
  • 54
  • 60
  • You could potentially use an `XmlAdapter` to handle this use case. The following article may help: http://blog.bdoughan.com/2011/08/xml-schema-to-java-generating.html – bdoughan Aug 24 '12 at 14:07
  • @BlaiseDoughan, this lets you format the value in the tag, but I don't see a way to customize the tag element itself, by adding an attribute. – Sam Barnum Aug 24 '12 at 16:17
  • possible duplicate of [Jaxb : Append field of Request XML without modfying JAXB java class](http://stackoverflow.com/questions/11827978/jaxb-append-field-of-request-xml-without-modfying-jaxb-java-class) – bdoughan Aug 24 '12 at 17:11

1 Answers1

0

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

Sam Barnum
  • 10,559
  • 3
  • 54
  • 60