Thursday, 26 February 2015

Xstream - Remove value tag



I've got the following xsd tag:



<xs:complexType name="documentation">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="language" use="required"/>
</xs:extension>
</xs:simpleContent>


this generates (with jax-b):



@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "documentation", propOrder = {
"value"
})
public class Documentation {

@XmlValue
protected String value;
@XmlAttribute(name = "language", required = true)
protected String language;


And I want some output like:



<documentation language="NL">SomeValue</documentation>


but Xstream generates:



<documentation language="NL">
<value>SomeValue</value>
</documentation>


how could I remove the value tags? I don't want them..


Code to generate the xml tags (this is just a snippet..):



private void createDocumentation(Description description, String docNL) {
List<Documentation> documentations = description.getDocumentation();
Documentation documentationNL = new Documentation();
documentationNL.setLanguage("NL");
documentationNL.setValue(docNL);
documentations.add(documentationNL);
}

private void createXmlFile(Description description) {

XStream xstream = new XStream(new DomDriver());
xstream.alias("description", Description.class);
xstream.alias("documentation", Documentation.class);

xstream.addImplicitCollection(Description.class, "documentation");
xstream.useAttributeFor(Documentation.class, "language");

String xml = xstream.toXML(description);
}

No comments:

Post a Comment