Dot-Net

xmlns 元素的順序是否重要

  • November 16, 2015

我不知道如何在Google上搜尋這個,但 xmlns 元素的問題在 XML 文件中重要嗎?我正在使用 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 規範

開始標籤或空元素標籤中屬性規範的順序並不重要。

所以不,這不重要,假設最終讀取您的 XML 的系統是兼容的。

引用自:https://stackoverflow.com/questions/18067491