XmlAttribute.Prefix 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定此節點的命名空間前綴。
public:
virtual property System::String ^ Prefix { System::String ^ get(); void set(System::String ^ value); };
public override string Prefix { get; set; }
member this.Prefix : string with get, set
Public Overrides Property Prefix As String
屬性值
此節點的命名空間前綴。 若無前綴,則此屬性回傳 String.Empty。
例外狀況
此節點為唯讀。
指定的前綴包含一個無效字元。
指定的前綴是malformed。
此節點的 namespaceURI 為 null。
指定的前綴為「xml」,而此節點的命名空間 URI 與「http://www.w3.org/XML/1998/namespace"」不同。
此節點為屬性,指定的前綴為「xmlns」,且該節點的 namespaceURI 與「http://www.w3.org/2000/xmlns/"」不同。
此節點為屬性,其限定名稱為「xmlns」[命名空間]。
範例
以下範例顯示屬性集合中每個節點的資訊。
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main(){
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book xmlns:bk='urn:samples' bk:genre='novel'>" +
"<title>Pride And Prejudice</title>" +
"</book>");
//Create an attribute collection.
XmlAttributeCollection attrColl = doc.DocumentElement.Attributes;
Console.WriteLine("Display information on each of the attributes... \r\n");
foreach (XmlAttribute attr in attrColl){
Console.Write("{0}:{1} = {2}", attr.Prefix, attr.LocalName, attr.Value);
Console.WriteLine("\t namespaceURI=" + attr.NamespaceURI);
}
}
}
Imports System.IO
Imports System.Xml
public class Sample
public shared sub Main()
Dim doc as XmlDocument = new XmlDocument()
doc.LoadXml("<book xmlns:bk='urn:samples' bk:genre='novel'>" & _
"<title>Pride And Prejudice</title>" & _
"</book>")
'Create an attribute collection.
Dim attrColl as XmlAttributeCollection = doc.DocumentElement.Attributes
Console.WriteLine("Display information on each of the attributes... ")
Dim attr as XmlAttribute
for each attr in attrColl
Console.Write("{0}:{1} = {2}", attr.Prefix, attr.LocalName, attr.Value)
Console.WriteLine(" namespaceURI=" + attr.NamespaceURI)
next
end sub
end class
備註
由於更改屬性的前綴不會改變其命名空間的 URI,因此更改已知有預設值的屬性前綴,並不會產生包含預設值與原始前綴的新屬性。