解析XMl时如何避免格式异常? [英] How to avoid format exception while parsing XMl?

查看:91
本文介绍了解析XMl时如何避免格式异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我使用Xml作为数据库存储数据。



如果文件大小很大,更新文件需要时间。



在那段时间内如果完成电源,那么XMl写操作就没有完成,XML被部分写入。



下次启动应用程序时,会抛出XML解析异常。



建议几种方法。

Hi,

I am using Xml as database for storing the data.

If the file size is to large it takes time to update the file.

In that time if power goes done then the XMl write operation is not completed and XML is partially written.

Next time when the application is launched then the XML parsing exception is thrown.

Suggest few ways.

推荐答案

如果数据库增长太多,我建议不要使用xml。 :)



但是,首先想到的是在开始更新de xml文件之前,制作副本(database.xml.bak)并删除它更新过程完成且没有错误。

如果由于任何原因它没有完成,在应用程序的每次启动时,您应检查.bak文件是否存在,在这种情况下,复制该文件覆盖数据库文件。



希望这可以让你了解它是如何完成的。
I suggest not using xml for a database if it's going to grow too much. :)

But well,what first comes to my mind is before starting to update de xml file, make a copy (database.xml.bak) and delete it if the update process completes without errors.
In case it doesn't complete for any reason, in every start of the application you should check if a .bak file exists and in that case,copy that file overwriting the database file.

Hope this gives you an idea of how it can be done.


这篇关于解析XMl时如何避免格式异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆