簡體   English   中英

為什么在節點的屬性中添加xmlns =“”?

[英]why add xmlns=“” in the attribute of a node?

我正在使用C#和XDcoument來添加節點根元素。 我用這個代碼:

XElement miAnimalNuevo = new XElement("PrincipalNode",
                new XAttribute("Atribute1", "value attribute 1"),
                new XAttribute("Attribute2", "value attribute 2"),
                new XElement("subNode","0000"));

但我明白了:

<PrincipalNode Atribute1="value attribute 1" Attribute2="value attribute 2" xmlns="">
    <subNode>0000</subNode>
  </PrincipalNode>

在屬性2之后,我看到xmlns =“”。 為什么? 我只想要屬性。

謝謝。

如果您的XML文檔在樹的某處定義了名稱空間,則會發生這種情況。

添加一個不在該命名空間但在空命名空間中的元素(即沒有命名空間 )將添加一個空的xmlns屬性。

<xml xmlns="some_namespace_uri">
  <foo>The foo element inherits the 'some_namespace_uri' namespace</foo>
  <bar xmlns="">The bar element is in no namespace</bar>
</xml>

相關: xmlns =“”是一個有效的xml命名空間嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM