XML 是一个轻量级数据库还是一个文档?
我一直认为 XML 是数据的来源,而不是数据的表示,但是我与营销人员一起工作,他们喜欢向客户推销 XML 是他们可以在浏览器中查看的文档的想法。我尝试解释说它只是数据组件,并且视图是独立的,但我使用这种方法取得的成功有限。我是否认为 XML 是一种数据存储?
I have always considered XML to be the source of data, not the presentation of data, however I have worked with marketing people that like selling the idea to customers that XML is a document that they can view in a browser. I try explaining that it is merely the data component, and that the view is separate, but I have had limited success with this approach. Am I far off in my assumption that XML is a data store?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您是对的:XML 不是一种表示语言。它旨在存储数据。
但是,这并不妨碍您利用其他技术(例如 XSL 和 CSS) 来格式化和呈现存储在 XML 文档中的数据。
You are correct: XML is not a presentation language. It is designed to store data.
However, that doesn't prevent you from leveraging additional technologies (such as XSL and CSS) to format and present the data that is stored in an XML document.
如今,您很难对 XML 是什么、不是什么,或者它应该用来做什么、不应该用来做什么做出任何简洁的陈述。有一些用于数据交换、应用程序配置、数据存储等 XML 的示例。这还没有考虑 OML、XAML 等改编。
回顾一下 XML 的起源可能会有所帮助,例如 这篇文章,以及一些批评经常被提出。
这是 Effective XML 作者的一段有趣的引述。
Well these days you'd be hard pressed to make any concise statement about what XML is and isn't or what it should and shouldn't be used for. There are examples of XML used for data exchange, app configuration, data storage, you name it. And that's without considering adaptations such as OML, XAML etc.
It might be helpful to look back at the origins of XML, such as this article, alongside some of the criticisms often raised.
And here's an interesting quote from the author of Effective XML.
XML 是一种存储数据的结构化方式。它既可以是数据库,也可以是文档。
从某种意义上说,它是一个数据库,它包含与某种格式匹配的数据,并且您可以读取或修改这些数据。
它是一种将一些数据存储在文件中的文档,如 Word 文档或 Photoshop 图像。
当然,它不是数据的表示,对于任何非 IT 人员来说,必须表示 XML 才能使用。
XML is a structured way to store data. It can be both database and document.
It's a database in the sense that it contains data which match a certain format, and you can read or modify this data.
It is a document in a way that it stores some data in a file, like Word document or Photoshop image.
Of course, it is not a presentation of data, and for any non-IT person, XML must be presented in order to be used.
顾名思义,XML 是(一种可扩展的)标记(语言)。您可以将它用于文档,在其中存储纯数据,天知道什么(严格来说,所有这些都是某种信息)。是的,它通常用于数据。但我认为它很少优于 JSON 或 YAML 等极其轻量级的数据格式 - 树非常强大,因此它们可以以相对较小的弯曲表示大多数数据,但它们并不是大多数数据的最自然表示。想想列表或键值对......您必须将它们建模为许多叶子或许多小分支,每个分支有两个叶子。
它不是传统意义上的数据库,至少不是一个高效的数据库。想一想:要从中获取数据,您需要完全解析它,同时构建一棵大树,然后搜索该树以获取所需的信息。是的,那是因为它太灵活了,但这正是问题所在。或者,当然,您使用 SAX 并使用更少的内存 - 但这仍然是线性搜索。
尽管将数据存储在与数据库无关的事物中可能很有用——同样是因为它的灵活性。
As the name says, XML is (an extensible) markup (language). You can use it for documents, to store plain data in it, for for god knows what (strictly speaking, all of these are some kind of information). It is commonly used for data, yes. But I think it's rarely superior to extremely lightweight data formats such as JSON or YAML - trees are very general powerful, so they can represent most data with relatively little bending, but they're not the most natural representation for most data. Think of lists or key-value pairs... you have to model those as lots of leaves or lots of small branches with two leaves each.
It's not a database in the traditional sense, at least not an efficient one. Think about it: To get data from it, you parse it completely, build a large tree while doing so, and then search that tree to get to the information you want. Yes, that's because it's so flexible, but that's exactly the problem. Or, of course, you use SAX and use less memory - but that's still linear search.
Although it can be useful to store data in a database-agnostic matter - again because of its flexibility.
XML 是一种数据格式。 HTML 是一种将 XML 用于文档的方法(通过赋予数据特定的含义)。 CSS 用于设置 HTML 样式。 XML 本身不做任何这些事情。它只是存储信息。某些浏览器将纯 XML 呈现为突出显示的树,但这不是 XML 的属性。这就是浏览器用它做的事情。您可以将CSS等添加到XML中,但这并不能确保它像这样显示。 XML本身只是一个数据容器。
XML is a data format. HTML is an approach to use XML for documents (by giving the data a specific meaning). CSS is used for styling HTML. XML itself does not do any of this. It just stores the information. Some browsers render plain XML as a highlighted tree, but that is not a property of XML. It is what the browser does with it. You can add CSS, etc to XML, but that does not ensure that it is displayed like that. XML itself is just a data container.