使用 Xstream 动态创建对象 (Java) [英] Using Xstream for dynamic creating object (Java)
本文介绍了使用 Xstream 动态创建对象 (Java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Xstream 来解析 XML 文件.
I am using Xstream to parse XML file.
XML 文件的理想格式是:
the ideal format of the XML file is:
<Line>
<P Name="Src">5</P>
<P Name="Dst">4</P>
</Line>
但是,有时,信息会是:
however, sometimes, the infomation would be:
<Line>
<P Name="Src">2</P>
<P Name="Points">[3, 0]</P>
<Branch>
<P Name="Points">[0, 8]</P>
<P Name="Dst">5</P>
</Branch>
<Branch>
<P Name="Dst">3</P>
</Branch>
</Line>
点部分可以忽略.
其实上面的信息就是一个fork line:
actually the above information means a fork line:
<Line>
<P Name="Src">2</P>
<P Name="Dst">5</P>
</Line>
<Line>
<P Name="Src">2</P>
<P Name="Dst">3</P>
</Line>
我可以使用 xstream 来实现这个目标吗?将分支拆分为两个 Line 对象?
Can I use xstream to achieve this objective? split the branch into two Line object?
推荐答案
我建议先使用 XSLT 转换输入 XML,然后使用 XStream 处理转换后的 XML:
I would suggest to first transform the input XML using XSLT and then process the transformed XML using XStream:
输入 XML -> XSLT
-> 转换后的 XML -> XStream
-> Java 对象
Input XML -> XSLT
-> Transformed XML -> XStream
-> Java object(s)
这篇关于使用 Xstream 动态创建对象 (Java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文