Freigeben über


XmlAttribute.NamespaceURI-Eigenschaft

Ruft den Namespace-URI dieses Knotens ab.

Namespace: System.Xml
Assembly: System.Xml (in system.xml.dll)

Syntax

'Declaration
Public Overrides ReadOnly Property NamespaceURI As String
'Usage
Dim instance As XmlAttribute
Dim value As String

value = instance.NamespaceURI
public override string NamespaceURI { get; }
public:
virtual property String^ NamespaceURI {
    String^ get () override;
}
/** @property */
public String get_NamespaceURI ()
public override function get NamespaceURI () : String

Eigenschaftenwert

Der Namespace-URI dieses Knotens. Wenn für dieses Attribut nicht explizit ein Namespace angegeben wird, gibt diese Eigenschaft String.Empty zurück.

Hinweise

Ein Attribut erbt den Namespace nicht von dem Element, an das es angefügt ist. Wenn für ein Attribut nicht explizit ein Namespace angegeben wird, wird der Namespace-URI als String.Empty angesehen.

Beispiel

Im folgenden Beispiel werden Informationen über die einzelnen Knoten in der Attributauflistung angezeigt.

Imports System
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
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);
    }
  }
}
#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 );
   }
}
import System.*;
import System.IO.*;
import System.Xml.*;

public class Sample
{
    public static void main(String[] args)
    {
        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.get_DocumentElement().get_Attributes();

        Console.WriteLine("Display information on each of the"
            + " attributes... \r\n");
        for (int iCtr = 0; iCtr < attrColl.get_Count(); iCtr++) {
            XmlAttribute attr = attrColl.get_ItemOf(iCtr);
            Console.Write("{0}:{1} = {2}", attr.get_Prefix(),
                attr.get_LocalName(), attr.get_Value());
            Console.WriteLine("\t namespaceURI=" + attr.get_NamespaceURI());
        }
    } //main
} //Sample

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

XmlAttribute-Klasse
XmlAttribute-Member
System.Xml-Namespace