编组和Android的解组XML文件 [英] marshalling and unmarshalling xml file in android
问题描述
我正尝试使用Android的春天来分析,看起来像上我的Android code XML(可序列化/反序列化对象从服务器流式传输和/或邮寄他们REST服务):
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:我已经读过其他线程是这样的:
<一href=\"http://stackoverflow.com/questions/1351218/unmarshalling-xml-files-into-java-objects-in-android\">Unmarshalling XML文件到Android中Java对象?
而此刻这看起来像我的情况下,最好的解决办法: http://simple.sourceforge.net
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.
推荐答案
的 Spring参考基本上回答你的问题:
The Spring reference basically answers your question:
2.2.4对象到XML封送
对象要在Spring的Android RestTemplate XML编组需要使用第三方的XML映射
图书馆。简单XML序列化来提供这种编组
功能。
Object to XML marshaling in Spring Android RestTemplate requires the use of a third party XML mapping library. The Simple XML serializer is used to provide this marshaling functionality.
最简单的方法是只要拿起这个建议,并简单去。我用它几次我自己,这是非常容易设置和声明有使用Java的POJO层次结构的一个相当简单的方式。 (在一个侧面说明:我还是preFER JSON虽然:))
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. :))
另外,它不会要求很多的努力来实现的(de)使用SAX序列,只要你的XML结构作为你的例子一样简单。此选项可能会保持你的code更加紧凑。
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.
这篇关于编组和Android的解组XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!