Using Xstream for dynamic creating object (Java)

僤鯓⒐⒋嵵緔 提交于 2019-12-11 05:19:28

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!