XmlAttribute.Prefix Proprietà

Definizione

Ottiene o imposta il prefisso dello spazio dei nomi del nodo.

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

Valore della proprietà

String

Prefisso dello spazio dei nomi del nodo. Se non è presente un prefisso, questa proprietà restituisce String.Empty.

Eccezioni

Il nodo è di sola lettura.

Il prefisso specificato contiene un carattere non valido.

Il prefisso specificato non è valido.

L'URI dello spazio dei nomi del nodo è null.

Il prefisso specificato è "xml" e l'URI dello spazio dei nomi del nodo è diverso da "http://www.w3.org/XML/1998/namespace".

Il nodo è un attributo, il prefisso specificato è "xmlns" e l'URI dello spazio dei nomi del nodo è diverso da "http://www.w3.org/2000/xmlns/".

Il nodo è un attributo e il valore qualifiedName del nome è "xmlns" [Namespaces].

Esempio

Nell'esempio seguente vengono visualizzate informazioni su ognuno dei nodi della raccolta di attributi.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlDocument^ doc = gcnew 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" );
   System::Collections::IEnumerator^ myEnum = attrColl->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      XmlAttribute^ attr = safe_cast<XmlAttribute^>(myEnum->Current);
      Console::Write( "{0}:{1} = {2}", attr->Prefix, attr->LocalName, attr->Value );
      Console::WriteLine( "\t namespaceURI={0}", attr->NamespaceURI );
   }
}
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

Commenti

Poiché la modifica del prefisso di un attributo non modifica l'URI dello spazio dei nomi, la modifica del prefisso di un attributo noto per avere un valore predefinito non crea un nuovo attributo con il valore predefinito e il prefisso originale.

Si applica a