Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

XmlAttribute.Prefix Property

Gets or sets the namespace prefix of this node.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)
public override string Prefix { get; set; }

Property Value

Type: System.String
The namespace prefix of this node. If there is no prefix, this property returns String.Empty.
ExceptionCondition
ArgumentException

This node is read-only.

XmlException

The specified prefix contains an invalid character.

The specified prefix is malformed.

The namespaceURI of this node is null.

The specified prefix is "xml", and the namespaceURI of this node is different from "http://www.w3.org/XML/1998/namespace".

This node is an attribute, the specified prefix is "xmlns", and the namespaceURI of this node is different from "http://www.w3.org/2000/xmlns/".

This node is an attribute, and the qualifiedName of this node is "xmlns" [Namespaces].

Because changing the prefix of an attribute does not change its namespace URI, changing the prefix of an attribute that is known to have a default value does not create a new attribute with the default value and the original prefix.

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

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.