【发布时间】:2011-07-23 22:40:10
【问题描述】:
我正在使用 xStream 来操作 XML。一切都好。放上 XML 存档和其他东西。但是,我有一个问题:
示例:我的 xml 包含一个标签,在这个标签中,我还有一些名为 <comment> 的标签。看一个示例代码:
<comments>
<comment>
<id>1</id>
<desc>A comment</desc>
</comment>
<comment>
<id>2</id>
<desc>Another comment</desc>
</comment>
<comment>
<id>3</id>
<desc>Another one comment</desc>
</comment>
</comments>
并且逐渐地。 我可以在标签内做 500 个标签。这些 cmets 属于注释类型。
如何使用 xStream 进行序列化以将所有这些标签放入类中?我不知道如何在类中让它接收各种对象。
显然,我将使用数组或其他方式来制作它。 但我不知道我该怎么做。
【问题讨论】:
-
您的 xml 看起来有点不对劲。
<comment>标签应该以</comment>标签结尾,而不是</comments>标签。另外,这就是你要找的东西吗:stackoverflow.com/questions/3136234/…? -
This question 也类似。
标签: java xml xml-parsing xstream