Android中使用XStream解析XML

作者注意到已有一篇关于Android环境下使用XStream解析XML文件的文章写得很好,因此决定不重复撰写。文章讨论了在尝试使用XStream时遇到的问题,并提供了关于如何正确使用XStream将对象转换为XML,以及当所写的XML与对象模式匹配时,XStream也能读取它的建议。

本来想写一篇在Android下使用XStream解析XML文件的文章,后来发现http://yunzhongxia.javaeye.com/blog/539827 已经写的很好了,所以就不写了。把地址记录下来。

使用XStream时注意到官方文档的一句话:

 

XStream fails to unmarshal my given XML and I do not know why?

By default XStream is written for persistence i.e. it will read the XML it can write. If you have to transform a given XML into an object graph, you should go the other way round. Use XStream to transfer your objects into XML. If the written XML matches your schema, XStream is also able to read it. This way is much easier, since you can spot the differences in the XML much more easy than to interpret the exceptions XStream will throw if it cannot match the XML into your objects.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值