XmlAttribute.NamespaceURI Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the namespace URI of this node.

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

public override string NamespaceURI { get; }

Property Value

Type: System.String

The namespace URI of this node. If the attribute is not explicitly given a namespace, this property returns String.Empty.

An attribute does not inherit its namespace from the element it is attached to. If an attribute is not explicitly given a namespace, the namespace URI is considered to be String.Empty.

The following example displays information on each of the nodes in the attribute collection.

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);
    }
  }
}

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Return to top
Show: