XML或自己的格式文件? [英] XML or own-format file?

查看:126
本文介绍了XML或自己的格式文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



对于XML(或其他标准),我看到:

在XML文件中保存信息时, / b>


  • (+)标准格式。
  • >


对于自己格式的文件,我看到:


  • ( - )我们需要构建一个自己的解析器(非标准的)。
  • (+)手动修改文件可以很容易

  • <



      使用XML时,
    • 需要在所有能够处理XML的应用程序之间共享

    • 自然树状结构

    • 以文本形式表示(二进制数据是基于文本格式的混合数据)
    • 可扩展性非常重要
    • 性能并不重要(解析XML并不是非常快速 - 尽管如果性能是重要的,并且您需要XML ,因为在最快和最慢之间存在很大的差异,所以请到处寻找快速解析器)
    • 架构可以被预先定义并且文件可以被验证

    • 更简单的格式(例如,名称=值对)不削减它
      基本上,如果在XML中有一个相当自然的数据模型表示,那么很可能是处理它的最简单的方法。如果您最终不得不乱用XML来适应它,请考虑其他格式。请注意,除XML以外,还有许多其他标准(或有点标准,例如多平台上的工具支持)。


      When is a good idea to save information in a XML file and when in a own-format file?

      For XML (or other standard) I see:

      • (+) Standard format.
      • (-) It's tedious to hand modify.

      For own-format files I see:

      • (-) We need to build a own-parser (non-standard).
      • (+) It can be easy to hand modify the files.

      解决方案

      Use XML when it's a good fit in various ways:

      • Need to share between different applications which are all capable of handling XML
      • Natural tree-like structure
      • Primarily data easily represented as text (binary data is a bit of a kludge in text-based formats)
      • Extensibility is important
      • Performance isn't critical (parsing XML isn't exactly blazingly fast - although if performance is important and you go for XML, shop around for a fast parser, as there's a wide difference between fastest and slowest)
      • Schema can be pre-defined and documents can be verified against it
      • Simpler formats (e.g. name=value pairs) don't cut it

      Basically if there's a pretty natural representation of your data model in XML, that may well be the easiest way of handling it. If you'd end up having to mess around a lot to fit it in with XML, think about other formats. Note that there are plenty of other standard (or "somewhat standard" - e.g. supported by tools on multiple platforms) formats available beyond just XML.

      这篇关于XML或自己的格式文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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