YAML 最适合什么类型的应用程序/利用?

发布于 2024-07-05 13:54:22 字数 85 浏览 12 评论 0原文

为什么人们会选择 YAML 而不是 XML 或任何其他格式?

Why would one choose YAML over XML or any other formats?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

故人的歌 2024-07-12 13:54:22

我同意塞尔吉奥的观点; YAML 提供了一种易于人类编辑的格式,也是清晰表示数据结构的好方法。

在我看来,YAML 往往更易于人类阅读。

YAML 更多的是一种数据序列化技术,而不是一种标记语言。

I agree with Sergio; YAML provides a format which is easily editable by humans, but also a good way to cleanly represent data structures.

YAML tends to be much more human-readable, IMO.

YAML is more of a data serialisation technique, rather than a markup language.

一人独醉 2024-07-12 13:54:22

YAML 的主要优点是人类可读性和紧凑性。 哦,它得到了各种平台和语言的广泛支持。

YAML 在 Ruby 社区中非常流行,在 Rails 和 Merb 等配置文件中,它主要优先于 XML 使用。

YAML's main advantages are human readability and compactness. Oh, and it's widely supported across various platforms and languages.

YAML is very popular in the Ruby community, where it's mainly used in preference to XML for configuration files in Rails and Merb for example.

彼岸花ソ最美的依靠 2024-07-12 13:54:22

如果文档需要由人编辑或创建,我会选择 YAML。 只是一个想法。

I would chose YAML if the documents needed to be edited or created by humans. Just a thought.

盛夏尉蓝 2024-07-12 13:54:22

YAML 最适合什么类型的应用程序/利用?

这很难明确回答。 相反,我将尝试提供一些 YAML 不适合的示例(以我的拙见)。

<name type="string">Orion</name>
<age type="integer">26</age>

在这种情况下,在 XML 中混合属性和值很有用。 YAML 没有属性,因此您必须使用类型推断来确定什么是日期/整数/字符串/等 - 对于复杂或用户定义的类型,这会失败。

<user>
  .... 10 lines of stuff
  <sub-user>
    ...15 more lines of stuff
  </sub-user>
  .... 10 more lines of stuff belonging to user
</user>

在这种情况下,XML 中的结束标记提供了很多好处。 如果您要在 YAML 中格式化上述数据,仅使用缩进来提供“范围”,则很难判断事物的开始和结束位置。

为了更好地衡量,这里引用了 yaml.org 上的官方 yaml 规范

YAML 主要是一种数据序列化语言。 XML 被设计为向后兼容标准通用标记语言 (SGML),因此有许多 YAML 所不具备的设计约束。 XML 继承了 SGML 的传统,旨在支持结构化文档,而 YAML 更紧密地针对数据结构和消息传递。 XML 是许多领域的先驱,而 YAML 则是从 XML 和其他技术中汲取经验教训的结果。

What type of application/utilization is YAML best suited for?

This is hard to clearly answer. Instead, I'll try provide some examples of what YAML isn't good for (in my humble opinion).

<name type="string">Orion</name>
<age type="integer">26</age>

This is a case of where it is useful to mix both attributes and values in XML. YAML doesn't have attributes, so you have to use type inference to decide what's a date/integer/string/etc - this fails for complex or user-defined types.

<user>
  .... 10 lines of stuff
  <sub-user>
    ...15 more lines of stuff
  </sub-user>
  .... 10 more lines of stuff belonging to user
</user>

This is a case where the closing tags in XML provide a lot of benefit. If you were to format the above data in YAML, using only indentation to provide 'scope', it would be a lot harder to tell where things start and end.

For good measure, here's a quote from the official yaml spec at yaml.org

YAML is primarily a data serialization language. XML was designed to be backwards compatible with the Standard Generalized Markup Language (SGML) and thus had many design constraints placed on it that YAML does not share. Inheriting SGML’s legacy, XML is designed to support structured documentation, where YAML is more closely targeted at data structures and messaging. Where XML is a pioneer in many domains, YAML is the result of lessons learned from XML and other technologies.

往事随风而去 2024-07-12 13:54:22

我使用 YAML 作为编写特定于域的语言的廉价且简单的替代品(特别是在其他开发人员将进行维护的情况下;我不确定当非开发人员维护它时我是否会使用它)

I use YAML as a cheap and easy replacement to writing a domain-specific language (particularly in cases where other developers will be doing maintenance; I'm not sure I'd use it when non-developers would be maintaining it)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文