2013-05-21 54 views
0

我有了下面的結構原始的XML:在根中命名空間的順序是否重要?可以訂購嗎?

<Root xmlns="http://xyz.com/2006/root" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xyz.com/2006/root.xsd"> 

要創建一個新的XML,我用這個代碼:

XNamespace ns = "http://xyz.com/2006/root"; 
      XNamespace xsiNs = "http://www.w3.org/2001/XMLSchema-instance"; 
      XDocument doc = new XDocument(
       new XDeclaration("1.0", "UTF-8", null), 
       new XElement(ns + "root", 
        new XAttribute(XNamespace.Xmlns + "xsi", xsiNs), 
        new XAttribute(xsiNs + "schemaLocation", 
         "http://xyz.com/2006/root.xsd"), 
      )); 

結果是:

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xyz.com/2006/root.xsd" xmlns="http://xyz.com/2006/root"> 

如何我們可以看到,在原來的xmls是第一個屬性,xmls:xsi是第二個,而xsi:schemalocation是最後一個。在新的XML中,順序是不同的。

我想知道,如果順序是重要的或不。

但是,要了解有關xml的更多信息,我想知道是否有任何方法來排序屬性。

謝謝。

回答

2

XML中屬性的順序(包括名稱空間聲明屬性)沒有意義。 XML處理工具不需要保留原始訂單。

+1

+1和更多細節在這裏是[參考 - 第3.1節](http://www.w3.org/TR/REC-xml/#sec-starttags) – NullPointer