我关注DTO
@XStreamAlias("outline")
public class OutlineItem implements java.io.Serializable {
private static final long serialVersionUID = -2321669186524783800L;
@XStreamAlias("text")
@XStreamAsAttribute
private String text;
@XStreamAsAttribute
@XStreamImplicit
private List<OutlineItem> childItems;
}
一旦我做了
XStream stream = new XStream();
stream.processAnnotations(OutlineItem.class);
stream.toXML(outlineItem.getChildItems()); //This is a List of all the child items
我将此作为输出文本
<List>
<outline text="Test Section1">
<outline text="Sub Section1 1">
</outline>
<outline text="Sub Section1 2">
</outline>
</outline>
<outline text="Test Section 2">
<outline text="Test Section2 1">
</outline>
</outline>
</List>
而我希望输出为:
<outline text="Test Section1">
<outline text="Sub Section1 1">
</outline>
<outline text="Sub Section1 2">
</outline>
</outline>
<outline text="Test Section 2">
<outline text="Test Section2 1">
</outline>
</outline>
如何摆脱Initial List标签?非常感谢任何帮助。
PS&GT;这是我问过几个星期back
的问题的延伸这可以通过XSLT实现吗?
答案 0 :(得分:0)
XSLT立即回答:
[XSLT 1.0]
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="List">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>