YAML 与 XML 的比较
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1308536/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
YAML compared to XML
提问by Iguramu
I read that after years yaml will be used instead of xml. Please compare the relative advantages and disadvantages of each specification.
我读到几年后将使用 yaml 而不是 xml。请比较每个规格的相对优缺点。
回答by Thom Smith
YAML is much less verbose. The signal-to-noise ratio is higher without all the brackets. This makes it subjectively easier to read and edit for many people. On the flip side, it's slightly (only slightly) harder to parse.
YAML 没有那么冗长。在没有所有括号的情况下,信噪比更高。这使得许多人主观上更容易阅读和编辑。另一方面,它稍微(只是稍微)难以解析。
The biggest difference, though, is that XML is meant to be a markup language and YAML is really more of a data format. Representing simple, hierarchical data tends to be more gracefully done in YAML, but actual marked-up text is awkward to represent.
不过,最大的区别在于 XML 旨在成为一种标记语言,而 YAML 实际上更像是一种数据格式。在 YAML 中表示简单的分层数据往往更优雅,但实际标记文本很难表示。
EDIT: I'd like to add, for reference, that YAML is essentially (though not historically) a "cleaner" version of JSON ("Javascript Object Notation") that largely eliminates the latter's perceived line noise (brackets and braces). If you can't find a suitable YAML library for a particular project, then JSON is a more widely-supported alternative with many of YAML's advantages.
编辑:我想补充一点,作为参考,YAML 本质上(尽管不是历史上)是 JSON(“Javascript 对象表示法”)的“更干净”版本,它在很大程度上消除了后者的感知线噪声(括号和大括号)。如果您无法为特定项目找到合适的 YAML 库,那么 JSON 是一种支持更广泛的替代方案,具有 YAML 的许多优点。
回答by cakeforcerberus
YAML is less verbose than XML; however, YAML is meant just for data and is not technically a markup language (YAML A'int Markup Language).
YAML 没有 XML 冗长;然而,YAML的意思只是数据,而不是技术上的标记语言(ŸAML一个“诠释中号arkup大号anguage)。
回答by RobF
A big plus for xml are the options to validate (opinions in parenthesis):
xml 的一大优点是验证选项(括号中的意见):
- Schematron (extremely powerful)
- W3C XML Schema (solid)
- DTD (not so nice (it isn't even xml))
- XSD (most used)
- Schematron(非常强大)
- W3C XML 模式(固体)
- DTD(不太好(它甚至不是 xml))
- XSD(最常用)
And options to query data:
以及查询数据的选项:
- XPath (in version 2.x even better)
- XQuery (mostly not of interest anymore)
- XPath(在版本 2.x 中更好)
- XQuery(大多不再感兴趣)
YAML is probably the easiest to read for humans in most cases.
在大多数情况下,YAML 可能是人类最容易阅读的。
JSON is quite easy to read and it is the way JavaScript stores data (correct me if wrong). I really like to use JSON when writing my own C style programming languages to parse values.
JSON 很容易阅读,它是 JavaScript 存储数据的方式(如果有误,请纠正我)。在编写自己的 C 风格编程语言来解析值时,我真的很喜欢使用 JSON。
回答by EBGreen
The main advantage that I see is that it is more easily human readable. I also like it a little better than XML because it has the concept of certain data structures (dictionaries and arrays) already built in.
我看到的主要优点是它更易于人类阅读。我也比 XML 更喜欢它,因为它已经内置了某些数据结构(字典和数组)的概念。
On the flip side, the library support for parsing YAML is nowhere near that of XML, so it is harder to use it to fulfill one of the prime uses of XML. That is inter-application communication.
另一方面,解析 YAML 的库支持远不及 XML,因此更难使用它来实现 XML 的主要用途之一。那就是应用间通信。
回答by Dominic Mitchell
I'm not so convinced about YAML being the future. Whilst I've used it, and it WorksForMe?, I have often seem complaints about the spec. The latest of which is Why I Don't Like YAML.
我不太相信 YAML 是未来。虽然我已经使用过它,而且它 WorksForMe?,但我似乎经常抱怨规范。最新的是为什么我不喜欢 YAML。

