【发布时间】:2015-02-26 13:55:52
【问题描述】:
我有以下 xsd 标签:
<xs:complexType name="documentation">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="language" use="required"/>
</xs:extension>
</xs:simpleContent>
这会生成(使用 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;
我想要一些输出,例如:
<documentation language="NL">SomeValue</documentation>
但 Xstream 生成:
<documentation language="NL">
<value>SomeValue</value>
</documentation>
如何删除值标签?我不要他们..
生成xml标签的代码(这只是一个sn-p..):
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);
}
【问题讨论】: