XML 文件比较
我已将 sqlite 数据库转移到 XML 文件。我正在处理数据库更新,因此当我从服务器获取一些 XML 文件时,我需要找到两个 XML 文件之间的差异,然后在我的手机数据库上应用更新。问题是如何成功比较两个xml文件?你看到什么方法了吗?
谢谢
I have transfered my sqlite database to an XML file. I am handling Database updates, so when I get some XML file from server, I need to find differences between the two XML files and then apply updates on my phone database. Problem is how to successfully compare two xml files? Do you see any approach?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
难道您不能假设所有数据都是新的,并且只获取最新的 xml 文件并将所有更新应用到相关记录吗?我知道这并不优雅,但根据您的情况,这可能是一个不错的选择。
Couldn't you just assume that all the data is new and just take the most recent xml file and apply all the updates to the relevant records? I know it's not elegant but depending on your situation, might be a good bet.
如果(且仅当)两个 XML 文件中的元素数量相同(不添加/删除行,仅更新值),您可以执行以下操作:
使用 XML 解析器(我使用 JDOM) 运行两个文件的所有元素,将一个值与另一个值进行比较。
注意:上面是用伪代码编写的,因此您必须自己计算出实际的代码 - 但我希望它给出了要做什么的一般概念。
还取决于 XML 文件的大小 - 上面的代码可能需要相当长的时间才能运行。
If (and only if) there are the same amount of elements in both XML-files (you don't add/remove rows, only update values), you could do the following:
Use an XML parser (I use JDOM) to run through all the elements of both files, comparing one value to the other.
Note: The above is written in pseudo-code, so you have to work out the actual code yourself - but I hope it gives a general idea of what to do.
Also depending on the size of your XML-files - the above could take quite some time to run.