XML vs YAML vs JSON [英] XML vs YAML vs JSON

查看:96
本文介绍了XML vs YAML vs JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我是从头开始的项目,它不依赖于任何其他项目. 我想使用一种格式来存储提要,例如XML,因为XML并不是同类中唯一可用的格式,所以我想知道:为什么我要选择其余的格式呢?

Assuming I'm starting a project from scratch, which is not dependent on any other project. I would like to use a format to store feeds, something like XML, since XML is not the only available format of its kind, I would like to know: why should I choose one over the rest?

我将使用perl.

"Feed"是对产品的描述(名称,价格,类型,简短描述,最多120个字).

'Feed' is a description of a product (name, price, type, short description, up to 120 words).

推荐答案

如果不了解更多信息,我们就无法真正回答.仅仅因为您当前不依赖于任何其他项目,您将来是否有可能与他们互动?如果是这样,他们更喜欢哪种技术?在BBC上,我们有一些仅JSON"项目,目的是发现想要访问我们的API的Java开发人员乞求我们只是提供一个简单的XML API,因为许多围绕XML构建的工具.他们甚至不关心名称空间,属性或其他任何东西.他们只是想要那些尖括号.

We can't really answer that without knowing a lot more. Just because you're not currently dependent on any other projects, are you likely to interact with them at some point in the future? If so, what technologies do they prefer? At the BBC, we've had some projects "JSON-only", only to find out that Java developers who wanted to access our API were begging us to provide a simple XML API simply because they have so many tool built around XML. They didn't even care about namespaces, attributes, or anything else; they just wanted those angle-brackets.

至于存储提要",我也不确定您的意思.您解释了提要中的数据,但是这些提要又将如何处理?解析它们?缓存并保留它们?把它们写成楔形文字片吗? :)

As for "storing feeds", I also not sure what you mean there. You explain the data in the feed, but what are you then going to do with those feeds? Parse them? Cache and reserve them? Write them out to cuneiform tablets? :)

听起来,您实际上想要的是数据库,并且您想要将数据保留在那里,以后再使其可序列化为JSON/YAML/XML或任何您想要的格式.我建议的是能够将数据提取到Perl数据结构中,然后使格式化程序"知道如何将数据结构序列化为所需的输出.这样,您可以序列化为JSON,如果以后还不够好的话,可以轻松地切换到YAML或其他方式.实际上,如果其他人需要您的数据(单向数据往往没有用),他们可以要求JSON,YAML,XML或其他任何东西.您具有更大的灵活性,并且不受您预先做出的决定的束缚.

I sounds like what you actually want is a database and you want to persist the data there and later make it serialisable as JSON/YAML/XML or whatever your desired format is. What I'd recommend is to be able to pull the data out into a Perl data structure and then have "formatters" which know how to serialise that data structure to the desired output. That way you can serialise to, say, JSON, and later if that's not good enough, easily switch to YAML or something else. In fact, if others need your data (one-way data tends not to be useful), they can ask for JSON, YAML, XML or whatever. You have more flexibility and aren't tied into a decision that you made up front.

话虽这么说,我不知道您的系统,所以很难说出正确的做法是什么.另外,并非JSON和YAML不能与XML完全互换.细微的差异可能会使您绊倒.

That being said, I don't know your system, so it's tough to say what the right thing to do is. Also, not that JSON and YAML aren't exactly interchangeable with XML. Subtle differences can and will trip you up.

这篇关于XML vs YAML vs JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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