为什么要使用XML作为存储格式? [英] Why use XML as a storage format?

查看:138
本文介绍了为什么要使用XML作为存储格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
何时可以使用XML文件来保存信息?

Possible Duplicate:
When is it OK to use an XML file to save information?

使用XML作为诸如配置文件之类的存储格式的所有内容是怎么回事?我问是因为[name retraced]框架有一个XML配置文件来存储数据库凭据,并且基于该框架构建的特定应用程序有一些菜单以XML片段的形式存储在数据库中……这不像我们共享的那样数据库凭据或其他菜单结构,甚至是多个服务将要使用的数据.全部是内部的/特定于此应用程序的.一位同事说XML是人类易于理解的格式...但是我认为那不是真的.与< password> foobar123</password>相比,INI文件中的密码foobar123对于人类来说更容易阅读.然后他说了有关解析的问题,但是INI文件已经存在了很长时间,所以我确定有一个或两个用于解析它们的库.我可以看到将其用作数据导出方法的逻辑,因为那样一来,无论应用程序产生什么,都可以由其他服务以直接的方式使用它,但是对于内部而言,我只是不了解.有人请赐教.

What's up with everything using XML as a storage format for configuration files such? I'm asking because [name retraced] framework has an XML configuration file to store database credentials, and the particular application that's built upon the framework has some menus stored as an XML fragment in a database... it's not like we'd share database credentials or or menu structure with others, or even data that would be consumed by multiple services. It's all internal/specific to this app. A coworker said that XML is an easily-readable format for humans... but I don't think that's true. password foobar123 in an INI file is easier for a human to read than <password>foobar123</password>. Then he said about parsing, but INI files have been around for ages so I'm sure there's a library or two for parsing them. I could see the logic behind using it as a data export method, because then whatever the app produces can be consumed by other services in a straightforward manner, but for internal stuff I just don't get it. Someone please enlighten me.

推荐答案

原因应为:

  • 互操作性(几乎任何东西都可以使用XML,但是在一个封闭的系统中,它一直存在,直到另一个应用程序必须能够读取它的那天)
  • 验证(XSD等)
  • 分层

实际原因:

  • 经理喜欢这个流行词&声称它与XML兼容"
  • 有这么多快乐的人声称它与XML兼容",以至于实际的开发人员开始认为这是一件好事

然后,JSON,YAML,csv或标准.ini等格式都有自己的位置.

Then again, formats like JSON, YAML, csv, or standard .ini all have their places.

这篇关于为什么要使用XML作为存储格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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