xmlns元素的顺序是否重要?

8

我不确定如何在Google上搜索此内容,但是在XML文件中,xmlns元素是否重要呢? 我正在使用ASP.NET(VB)中的XMLWriter创建XML文件,并尝试匹配我收到的示例。

<ns2:SubmitSMReq xmlns:ns4="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns3="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-6-MM7-1-4" xmlns:ns2="http://somesite/schema">

这是我在VB文件中的内容:

writer.WriteStartElement("ns2", "SubmitSMReq", "http://schemas.xmlsoap.org/soap/envelope/")
writer.WriteAttributeString("xmlns", "ns3", Nothing, "http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-6-MM7-1-4")
writer.WriteAttributeString("xmlns", "ns4", Nothing, "http://somesite/schema")

但它生成的XML格式不同。
<ns2:SubmitSMReq xmlns:ns3="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-6-MM7-1-4" xmlns:ns4="http://somesite/schema" xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/">

我意识到提供的例子中xmlns具有不同的“ns”(命名空间?)数字。这些东西有关系吗?我的文件是否没问题?

谢谢。


我不确定我理解这个问题 - 生成的 XML 是您告诉程序要生成的内容(您使用 ns3 然后是 ns4)。如果您想使其与示例匹配,请交换 ns3 和 ns4 行的顺序。 - Tim
1
你有没有遇到过那种周一?我将它改成了: writer.WriteStartElement("ns2", "SubmitSMReq", "http://somesite/schema") writer.WriteAttributeString("xmlns", "ns4", Nothing, "http://schemas.xmlsoap.org/soap/envelope/") writer.WriteAttributeString("xmlns", "ns3", Nothing, "http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-6-MM7-1-4"), 看起来完美无缺。 - gm77
是的 - 今天我自己也遇到了这种情况(但不是与代码有关) :) - Tim
希望你的一天也能变得更好。再次感谢。 - gm77
1个回答

9

根据XML规范的最新版本

在开始标记或空元素标记中属性规范的顺序是不重要的。

因此,假设最终读取您的XML的系统符合规范,那么属性顺序应该不会影响结果。


谢谢,我会尽快让我的问题得到解答。 - gm77

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接