We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(14)
XML 确实有很多替代方案,但其中许多方案的主要问题似乎是库可能不适用于每种选择的语言,而且库的实现相对费力。
如果与键值对(例如哈希表)相比,解析树结构本身可能并不那么令人愉快。 如果一个哈希表实例满足所有键都是字符串且所有值都是字符串的要求,那么实现 hashtable2string() 和 string2hashtable() 就相对不费力。
我一直在 PHP 和 JavaScript 之间的 AJAX 中使用哈希表序列化,我开发的格式称为 ProgFTE(程序员友好的文本交换),描述如下:
http://martin.softf1.com/g/n//a2/doc/progfte/index.html
人们可以在 Kibuvits Ruby 库中找到 ProgFTE 实现的 Ruby 版本:
http://rubyforge.org/projects/kibuvits/
There are truly plenty of alternatives to XML, but the main problem with many of them seems to be that libraries might not be available for every language of choice and the libraries are relatively laborious to implement.
Parsing a tree structure itself might not be that pleasant, if compared to key-value pairs, e.g. hash tables. If a hash table instance meets the requirement that all of its keys are strings and all of its values are strings, then it's relatively non-laborous to implement hashtable2string() and string2hashtable().
I've been using the hash table serialization in AJAX between PHP and JavaScript and the format that I've developed, is called ProgFTE (Programmer Friendly text Exchange) and is described at:
http://martin.softf1.com/g/n//a2/doc/progfte/index.html
One can find a Ruby version of the ProgFTE implementation as part of the Kibuvits Ruby Library:
http://rubyforge.org/projects/kibuvits/
如果您对尖括号过敏,则可以使用 JSON、HDF (ClearSilver) 和OGDL 是我唯一知道的。
经过一番谷歌搜索后,我还在这里找到了替代方案列表:
http://web.archive.org/web/20060325012720/ www.pault.com/xmlalternatives.html
If you're allergic to angle brackets, then JSON, HDF (ClearSilver), and OGDL are the only ones I know offhand.
After a bit of googling, I also found a list of alternatives here:
http://web.archive.org/web/20060325012720/www.pault.com/xmlalternatives.html
AFAIK、JSON 和 YAML 在数据结构方面完全相同。 YAML 只是少了括号、引号之类的东西。 所以我不明白你是如何拒绝一个而保留另一个的。
另外,我不明白 XML 的尖括号为何不如 JSON 的方括号、大括号和引号“人类可读”。
AFAIK, JSON and YAML are exactly equivalent in data structure terms. YAML just has less brackets and quotes and stuff. So I don't see how you are rejecting one and keeping the other.
Also, I don't see how XML's angle brackets are less "human readable" than JSON's square brackets, curly brackets and quotes.
YAML 是一种功能极其齐全且通常是人类可读的格式,但它的致命弱点是复杂性,正如我们今年冬天看到的 Rails 漏洞所证明的那样。 由于 Ruby 作为一种配置语言无处不在,Github 出名的 Tom Preston-Werner 开始创建一个名为 TOML 的明智替代方案。 它立即获得了巨大的关注并拥有强大的工具支持。 我强烈建议任何查看 YAML 的人都检查一下:
https://github.com/mojombo/toml
YAML is extremely fully-featured and generally human-readable format, but it's Achilles heal is complexity as demonstrated by the Rails vulnerabilities we saw this winter. Due to its ubiquity in Ruby as a config language Tom Preston-Werner of Github fame stepped up to create a sane alternative dubbed TOML. It gained massive traction immediately and has great tool support. I highly recommend anyone looking at YAML check it out:
https://github.com/mojombo/toml
对于存储类似代码的数据,LES(Loyc 表达式语法)是一种新兴的替代方案。 我注意到很多人使用 XML 来构建类似代码的结构,例如支持条件、命令调用、有时甚至是循环的构建系统。 这些事情在 LES 中看起来很自然:
不过,它还没有很好的工具支持; 目前唯一的 LES 库是针对 C# 的。 目前已知只有一个应用程序使用 LES:LLLPG< /a>. 它支持“属性”,但它们就像 C# 属性或 Java 注释,而不是 XML 属性。
理论上,您可以使用 LES 来处理数据或标记,但没有关于如何执行此操作的标准:
For storing code-like data, LES (Loyc Expression Syntax) is a budding alternative. I've noticed a lot of people use XML for code-like constructs, such as build systems which support conditionals, command invocations, sometimes even loops. These sorts of things look natural in LES:
It doesn't have great tool support yet, though; currently the only LES library is for C#. Currently only one app is known to use LES: LLLPG. It supports "attributes" but they are like C# attributes or Java annotations, not XML attributes.
In theory you could use LES for data or markup, but there are no standards for how to do that:
我会推荐 JSON ...但既然你已经提到过它也许你应该看看 Google 协议缓冲区。
编辑:协议缓冲区是为了以编程方式使用(有 c++、java、python ...的绑定),因此它们可能不适合您的目的。
I would recommend JSON ... but since you already mentioned it maybe you should take a look at Google protocol buffers.
Edit: Protocol buffers are made to be used programatically (there are bindings for c++, java, python ...) so they may not be suited for your purpose.
我认为 Clearsilver 是一个非常好的选择。 他们甚至在此处提供了一个比较页面以及使用它的项目
I think Clearsilver is a very good alternative. They even have a comparison page here and a list of projects that use it
你的要求有点不可能......你想要一些接近 XML 的东西,但拒绝可能最接近的没有尖括号 (YAML) 的等价物。
尽管我非常不喜欢它,但为什么不直接使用 XML 呢? 您不必真正阅读 XML(我想除了调试之外),有大量的工具可以用于它。
几乎所有非 XML 的内容都不会得到广泛使用,因此工具支持也会减少。
JSON 可能是等价的,但它几乎同样不可读......但同样,你不应该真正阅读它(将它加载到你正在使用的任何语言中,并且它应该转换为本机数组/字典/变量/任何)。
哦,我确实发现 JSON 比 XML 更容易解析:我在 Javascript 中使用过它,还有 simplejson Python 模块 - 大约一个命令,它很好地转换为本地 Python 字典或 Javascript对象(因此得名!)
You're demands are a bit impossible.. You want something close to XML, but reject probably the closest equivalent that doesn't have angle-bracket (YAML).
As much as I dislike it, why not just use XML? You shouldn't ever have to actually read XML (aside from debugging, I suppose), there are an absurd amount of tools about for it.
Pretty much anything that isn't XML isn't going to be as widely used, thus there will be less tool support.
JSON is probably about equivalent, but it's pretty much equally unreadable.. but again, you shouldn't ever have to actually read it (load it into whatever language you are using, and it should be transformed into native arrays/dicts/variables/whatever).
Oh, I do find JSON far nicer to parse than XML: I've used it in Javascript, and the simplejson Python module - about one command and it's nicely transformed into a native Python dict, or a Javascript object (thus the name!)
我发现 S-Expressions 是表示结构化数据的好方法。 这是一种非常简单的格式,易于生成和解析。 它不支持属性,但像 YAML & JSON,不需要。 属性只是 XML 限制冗长的一种方式。 更简单、更干净的格式只是不需要它们。
I have found S-Expressions to be a great way to represent structured data. It's a very simple format which is easy to generate and parse. It doesn't support attributes, but like YAML & JSON, it doesn't need to. Attributes are simply a way for XML to limit verbosity. Simpler, cleaner formats just don't need them.
Jeff 在此处和这里。 这应该可以帮助您入门。
Jeff wrote about this here and here. That should help you get started.
AXON 涵盖了 XML 和 JSON 的精华。 让我们用几个例子来解释这一点。
AXON 可以被认为是 XML 数据的较短形式。
XML
AXON
XML
AXON
AXON 包含某种形式的 JSON。
JSON
AXON
AXON 可以表示类似 XML 和 XML 的组合。类似JSON的数据。
AXON
现在有Python库pyaxon可用。
There is AXON that cover the best of XML and JSON. Let's explain that in several examples.
AXON could be considered as shorter form of XML data.
XML
AXON
XML
AXON
AXON contains some form of JSON.
JSON
AXON
AXON can represent combination of XML-like and JSON-like data.
AXON
There is available the python library pyaxon now.
TL;DR
Prolog 在这里没有被提及,但它是我所知道的表示数据的最佳格式。 Prolog 程序本质上描述数据库,实体之间具有复杂的关系。 Prolog 解析起来非常简单,它唯一的竞争对手可能是这个领域的 S 表达式。
完整版本
程序员经常“忘记”XML 实际由什么组成。 通常指的是它的一个很小的子集。 XML 是一种非常复杂的格式,至少包含以下部分:DTD 架构语言、< a href="https://www.w3.org/TR/xmlschema11-1/" rel="noreferrer">XSD 架构语言,XSLT 转换语言, RNG 架构语言 和 XPath(加上 XQuery)语言- 它们都是 XML 标准的重要组成部分。 另外,还有一些伪经,例如 E4X。 每一个都有自己的版本,有相当多的重叠、不兼容性等。很少有 XML 解析器能够实现所有这些版本。 更不用说流行解析的多个怪癖和错误,其中一些会导致显着的安全问题,例如 https://en .wikipedia.org/wiki/XML_external_entity_attack。
因此,寻找 XML 替代方案并不是一个好主意。 您可能根本不想处理 XML 之类的东西。
YAML 可能是第二差的选择。 它不像 XML 那么大,但它的设计也是为了尝试覆盖所有基础……每个基础超过十次……以任何人都无法想象的不同且独特的方式。 我还没有听说过可以正常工作的 YAML 解析器。 Ruby 是一种大量使用 YAML 的语言,其著名的 因为它而搞砸了。 迄今为止我见过的所有 YAML 解析器都是 libyaml 的副本,它本身就是手写的(不是一种从正式描述生成的解析器,其代码很难验证其正确性(函数跨越数百行,控制流复杂)。 正如已经提到的,它完全包含 JSON...在同一个文档中的一些 Unicode 编码技术之上...以及可能还有一堆您不想听到的其他内容。
另一方面,JSON 与其他两者完全不同。 您可以在等待从 Maven Nexus 下载 JSON 解析器工件时编写一个 JSON 解析器。 它能做的事情很少,但至少你知道它的能力。 没有什么惊喜。 (除了与字符串和双精度编码中的字符转义相关的一些差异)。 没有秘密的利用。 您不能在其中写评论。 多行字符串看起来很糟糕。 无论您所说的属性和属性之间的区别是什么意思,您都可以通过更多嵌套的字典来实现。
假设,尽管您想要纠正 XML 的错误……好吧,那么像 YAML 或 JSON 这样流行的东西就无法做到这一点。 不知何故,时尚和理性思维在七十年代中期的某个时候在编程中分道扬镳。 所以,你必须回到一切从麦卡锡、霍尔、科德和科瓦尔斯基开始的地方,弄清楚你想要代表什么,然后看看对于你是谁来说,最好的代表技术是什么试图代表:)
TL;DR
Prolog wasn't mentioned here, but it is the best format I know of for representing data. Prolog programs, essentially, describe databases, with complex relationships between entities. Prolog is dead-simple to parse, whose probably only rival is S-expressions in this domain.
Full version
Programmers often "forget" what XML actually consists of. Usually referring to a very small subset of what it is. XML is a very complex format, with at least these parts: DTD schema language, XSD schema language, XSLT transformation language, RNG schema language and XPath (plus XQuery) languages - they all are part and parcel of XML standard. Plus, there are some apocrypha like E4X. Each and every one of them having their own versions, quite a bit of overlap, incompatibilities etc. Very few XML parsers in the wild implement all of them. Not to mention the multiple quirks and bugs of the popular parses, some leading to notable security issues like https://en.wikipedia.org/wiki/XML_external_entity_attack .
Therefore, looking for an XML alternative is not a very good idea. You probably don't want to deal with the likes of XML at all.
YAML is, probably, the second worst option. It's not as big as XML, but it was also designed in an attempt to cover all bases... more than ten times each... in different and unique ways nobody could ever conceive of. I'm yet to hear about a properly working YAML parser. Ruby, the language that uses YAML a lot, had famously screwed up because of it. All YAML parsers I've seen to date are copies of libyaml, which is itself a hand-written (not a generated from a formal description) kind of parser, with a code which is very difficult to verify for correctness (functions that span hundreds of lines with convoluted control flow). As was already mentioned, it completely contains JSON in it... on top of a handful of Unicode coding techniques... inside the same document, and probably a bunch of other stuff you don't want to hear about.
JSON, on the other hand, is completely unlike the other two. You can probably write a JSON parser while waiting for downloading JSON parser artefact from your Maven Nexus. It can do very little, but at least you know what it's capable of. No surprises. (Except some discrepancies related to character escaping in strings and doubles encoding). No covert exploits. You cannot write comments in it. Multiline strings look bad. Whatever you mean by distinction between properties and attributes you can implement by more nested dictionaries.
Suppose, though you wanted to right what XML wronged... well, then the popular stuff like YAML or JSON won't do it. Somehow fashion and rational thinking parted ways in programming some time in the mid seventies. So, you'll have to go back to where it all began with McCarthy, Hoare, Codd and Kowalski, figure out what is it you are trying to represent, and then see what's the best representation technique there is for whatever is that you are trying to represent :)
JSON 是一个非常好的替代方案,并且有多种语言的工具。 而且它在 Web 客户端中使用起来非常简单,因为它是原生 JavaScript。
JSON is a very good alternative, and there are tools for it in multiple languages. And it's really easy to use in web clients, as it is native javascript.
YAML 是 JSON 的 100% 超集,因此拒绝 YAML 然后考虑 JSON 是没有意义的。 YAML 可以完成 JSON 所做的一切,但 YAML 还提供更多功能(例如引用)。
除了使用 DTD 验证文档之外,我想不出 XML 可以做而 YAML 不能做的任何事情,根据我的经验,这从来不值得花费这些开销。 但 YAML 比 XML 更快、更容易输入和读取。
至于属性或属性,如果你仔细想想,它们并没有真正“添加”任何东西......这只是一种符号快捷方式,将某些东西写为节点的属性,而不是将其放入自己的子节点中。 但如果您喜欢这种便利,通常可以使用 YAML 的内联列表/哈希来模拟它。 例如:
对我来说,不必将每个节点标签编写两次,再加上没有尖括号垃圾,这使得 YAML 成为首选。 我实际上也喜欢缺乏正式的标签属性,因为在我看来,这总是像 XML 的灰色区域,不必要地为本质上相同的概念引入了两套语法(在编写和遍历时)。 YAML 完全消除了这种混乱。
YAML is a 100% superset of JSON, so it doesn't make sense to reject YAML and then consider JSON instead. YAML does everything JSON does, but YAML gives so much more too (like references).
I can't think of anything XML can do that YAML can't, except to validate a document with a DTD, which in my experience has never been worth the overhead. But YAML is so much faster and easier to type and read than XML.
As for attributes or properties, if you think about it, they don't truly "add" anything... it's just a notational shortcut to write something as an attribute of the node instead of putting it in its own child node. But if you like that convenience, you can often emulate it with YAML's inline lists/hashes. Eg:
For me, the luxury of not having to write each node tag twice, combined with the freedom from all the angle-bracket litter makes YAML a preferred choice. I also actually like the lack of formal tag attributes, as that always seemed to me like a gray area of XML that needlessly introduced two sets of syntax (both when writing and traversing) for essentially the same concept. YAML does away with that confusion altogether.