为什么人们接受 XSD 需要特定顺序的元素? [英] Why do people accept XSD requiring elements in a particular order?

查看:26
本文介绍了为什么人们接受 XSD 需要特定顺序的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在最近的一项工作任务中,我一直在构建 XML 与 .NET 应用程序交互的 PHP 端(使用 SimpleXMLElement).我一直在与 .NET 领域的同行在概念思维方面遇到差异,特别是因为他们只是在 .NET 中使用 XSD/XML 库而没有考虑太多,而我发现自己不得不向后弯腰,因为XSD 的局限性.换句话说,如果我以错误"的顺序提供元素或包含它不知道的元素,我无法理解为什么他们的 XML 摄取器会失败,而且他们不明白我为什么关心.(相反,我对他们的开发实践的看法降低了因为他们不想关心.)

In a recent task at work, I've been building the PHP end (using SimpleXMLElement) of an XML interaction with a .NET app. I've been encountering differences in conceptual thinking with my counterparts in .NET land, specifically because they're just using the XSD/XML libraries in .NET without thinking much about that, whilst I'm finding myself having to bend over backwards because of XSD's limitations. In other words, I couldn't understand why their XML ingestor falls over if I give elements in the 'wrong' order or has ones it doesn't know about, and they don't understand why I care. (Instead my opinion of their development practices is lowered because they don't want to care.)

盲目接受 XSD 生成是真正的罪魁祸首吗?为什么人们接受它如此挑剔?

Is blind acceptance of XSD generation the real culprit here? Why do people accept it being so fussy?

推荐答案

XSD 不要求元素按特定顺序排列,它只是允许您坚持元素按特定顺序排列.

XSD doesn't require elements to be in a particular order, it just allows you to insist that elements be in a particular order.

强制元素按特定顺序排列的一个好处是,如果您实际上是手动编辑 XML,则智能感知会自动假定您需要按特定顺序排列的下一个标签.如果你只使用 xs:all 而不是 xs:sequence,智能感知将列出所有可能的下一个元素,你必须选择哪一个(或 选择,取决于你的观点:)).

One thing that's nice about forcing elements to be in a particular order is that, if you are actually hand-editing XML, the intellisense will automatically assume you want the next tag in the particular order. If you just use xs:all instead of xs:sequence, the intellisense will list all the possible next elements, and you will have to choose which one (or get to choose, depending on your perspective :)).

我还要补充一点,使用固定顺序可以使 XML 文件对用户更友好.确实,无论您对坐标 x、y、z 还是 z、y、x 进行排序,对文件中的软件读取应该没有区别,但是如果顺序遵循通用约定,那么人类读取这些坐标会更容易.如果所有内容都按相同顺序排列,那么人类也可以更轻松地比较两个 XML 文件以查看它们的不同之处.

I would also add that, using a fixed order makes the XML files more user friendly to work with. True, it should make no difference to the software reading in the file whether you order your coordinates x, y, z or z, y, x, but a human reading these coordinates would have an easier time if the order follows common convention. It's also easier for a human to compare two XML files to see what's different about them if everything is in the same order.

简单来说一下这个问题,使用固定顺序有什么缺点?:)

Just to turn the question on its head, What is the disadvantage of using a fixed order? :)

这篇关于为什么人们接受 XSD 需要特定顺序的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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