xml 中不需要的元素
我就会得到以下 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>
如何摆脱初始列表标签?非常感谢任何帮助。
PS>这是我几周前问过的问题的延伸返回
可以这完全可以通过 XSLT 来实现吗?
I have following 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;
}
once i do
XStream stream = new XStream();
stream.processAnnotations(OutlineItem.class);
stream.toXML(outlineItem.getChildItems()); //This is a List of all the child items
i get this as my output text
<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>
whereas i want the output to be:
<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>
How do i get rid of the Initial List tag? any help is greatly appreciated.
PS> This is a extension of the question i had asked a couple of weeks back
Can this be achieved by XSLT at all?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
XSLT 答案很直接:
[XSLT 1.0]
The XSLT answer is immediate:
[XSLT 1.0]