Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

XmlAttribute.Value Property

Gets or sets the value of the node.

[Visual Basic]
Overrides Public Property Value As String
[C#]
public override string Value {get; set;}
[C++]
public: __property String* get_Value();
public: __property void set_Value(String*);
[JScript]
public override function get Value() : String;
public override function set Value(String);

Property Value

The value returned depends on the NodeType of the node. For XmlAttribute nodes, this property is the value of attribute.

Exceptions

Exception Type Condition
ArgumentException The node is read-only and a set operation is called.

Example

[Visual Basic, C#, C++] The following example displays information on each of the nodes in the attribute collection.

[Visual Basic] 
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

[C#] 
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);
    }
  }
}

[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;

int main()
{
  
    XmlDocument* doc = new XmlDocument();
    doc->LoadXml(S"<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(S"Display information on each of the attributes... \r\n");
    System::Collections::IEnumerator* myEnum = attrColl->GetEnumerator();
    while (myEnum->MoveNext())
    {
       XmlAttribute* attr = __try_cast<XmlAttribute*>(myEnum->Current);
       Console::Write(S"{0}:{1} = {2}",attr->Prefix,attr->LocalName,attr->Value);
       Console::WriteLine(S"\t namespaceURI={0}", attr->NamespaceURI);
    }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

XmlAttribute Class | XmlAttribute Members | System.Xml Namespace

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft