问题
I am using Xstream to parse XML file.
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>
The Points part could be ignored.
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>
Can I use xstream to achieve this objective? split the branch into two Line object?
回答1:
I would suggest to first transform the input XML using XSLT and then process the transformed XML using XStream:
Input XML -> XSLT
-> Transformed XML -> XStream
-> Java object(s)
来源:https://stackoverflow.com/questions/20798905/using-xstream-for-dynamic-creating-object-java