XML 关心元素的顺序吗? [英] Does XML care about the order of elements?

查看:29
本文介绍了XML 关心元素的顺序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

XML 有时让我感到困惑,但我正在努力弄清楚这一点.供应商告诉我的没有意义,但 XML 和我不相处:)

XML confuses me sometimes, but I'm trying to get this figured out. What the vendor is telling me doesn't make sense but again, XML and I don't get along :)

我将一些 XML 发送到供应商的 Web 服务,该服务给我带来了随机故障:

I have some XML that I'm sending to a vendor's web service that is giving me random failures:

<root>
    <Request>
        <Driver id="1" VehId="1">...</Driver>
        <Driver id="2" VehId="1">...</Driver>
        <Driver id="3" VehId="2">...</Driver>
        <Vehicle id="1">...</Vehicle>
        <Vehicle id="2">...</Vehicle>
        <Driver id="4" VehId="2">...</Driver>
    </Request>
</root>

没有 XSLT 或 XSD 可用于比较以查看我的 XML 是否有效.

There is no XSLT or XSD to compare against to see if my XML is valid.

供应商声明 XML 无效,因为驱动程序 #4 位于错误区域.Driver 的 XPath 应该是 root/Request/Driver,Vehicle 应该是 root/Request/Vehicle.

The vendor states that the XML is invalid because Driver #4 is in the wrong area. The XPath for Driver should be root/Request/Driver and Vehicle is root/Request/Vehicle.

XML 解析器强制元素顺序是否常见,尤其是在没有 XSD 来比较 XML 的情况下?供应商的支持回复我很慢,所以我想知道什么是好的常见做法.

Is it common that XML parsers would force an element order, especially if there is no XSD to compare the XML to? The vendor's support is slow to get back with me, so I want to know what good common practice is.

跟进

我向我们的客户代表抱怨说无法对此进行测试(并且听起来他们只是想获得支持资金),结果证明开发人员拥有 XSD,但支持人员没有.所以我一直在和错误的群体说话 *facepalm*

I complained enough to our account rep about not being able to test this (and made it sound like they were just trying to get support money) that it turns out that the Developers have the XSD, but Support doesn't. So I had been talking to the wrong group *facepalm*

我得到了 XSD,它确实强制执行特定的元素顺序.

I got the XSD, and it does enforce a specific order of elements.

现在就他们自己的示例 XML 与他们作斗争并不遵循模式,但至少现在我有一些东西可以测试.

Now to fight them in regards to their own sample XML doesn't follow the schema, but at least now I have something to test against.

推荐答案

如果手头没有 XSD(XML 架构),那么您只能检查您的 XML 格式是否正确.

If there is no XSD (XML schema) at hand, then all you can check for is whether or not your XML is well formed.

在你的情况下 - 是的.没有重叠的 XML 标签、没有打开的 XML 标签或任何类似的东西.

In your case - it is. There are no overlapping XML tags, no XML tag that are left open or anything of that sort.

如果供应商需要在 XML 中强制执行诸如顺序之类的事情,他应该提供一个 XSD 文件 - 否则,无法验证和检查他的要求"....

If the vendor needs to enforce things like order inside the XML, he ought to provide an XSD file - otherwise, his "requirements" cannot be validated and checked....

这篇关于XML 关心元素的顺序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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