Android 中的编组和解组 xml 文件
我正在尝试使用 spring android 来解析一个类似于我的 android 代码的 xml(序列化/反序列化从服务器流式传输的对象和/或将它们发送到 REST 服务):
<ROOT>
<USERNAME>user</USERNAME>
<INFOTYPE></INFOTYPE>
<DATA format='xml_field'>
<field name='field_id1'>1000</field>
<field name='field_id2'>xxx</field>
</DATA>
</ROOT>
我不知道它是否会有可能,但我真的很喜欢这个工具(spring android)。
但是,我会接受任何可以解决我的问题的简单解决方案。
ps:我已经读过这样的其他线程: 在 Android 中将 XML 文件解组为 Java 对象? 目前,这看起来是适合我的情况的最佳解决方案:http://simple.sourceforge.net。
I´m trying to use spring android to parse an xml that looks like that on my android code (to serialize/deserialize objects streaming from server and/or send them in post to the REST service):
<ROOT>
<USERNAME>user</USERNAME>
<INFOTYPE></INFOTYPE>
<DATA format='xml_field'>
<field name='field_id1'>1000</field>
<field name='field_id2'>xxx</field>
</DATA>
</ROOT>
I don´t know if it would be possible, but I really like this tool (spring android).
However, I would accept any easy solution that addresses my issue.
ps: I've already read other threads like this:
Unmarshalling XML files into Java objects in Android?
and at the moment this looks like the best solution for my case: http://simple.sourceforge.net.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上 Spring 参考回答你的问题:
最简单的方法就是接受这个建议并选择 Simple。我自己已经使用过几次,它非常容易设置,并且有一种相当简单的方法来使用 Java POJO 声明层次结构。 (顺便说一句:不过我仍然更喜欢 JSON。:))
或者,如果您的 xml 结构像您的示例一样简单,那么使用 SAX 实现(反)序列化不需要花费很多精力。此选项可能会使您的代码更加紧凑。
The Spring reference basically answers your question:
The easy way is to just pick up this suggestion and go with Simple. I've used it a couple of times myself and it's very easy to set up and has a fairly straightforward way of declaring the hierarchy using Java POJOs. (On a side note: I still prefer JSON though. :))
Alternatively it wouldn't require a lot of effort to implement (de)serializing using SAX, provided your xml structures are as simple as your example. This option will probably keep your code more compact.