ReadAttributeValue Method
Namespace
System.Xml
Assembly
System.Xml.ReaderWriter.dll
Syntax
public bool ReadAttributeValue();
Summary
Advances the XmlNodeReader
to the next attribute value, if the reader is positioned on an attribute node. Returns true
if the reader is positioned on an attribute value; otherwise, false
.
Return Value
Type: System.Boolean
Returns true
if the current node is an attribute value after the read operation; otherwise, false
.
Remarks
When the reader is positioned on an attribute node, calling ReadAttributeValue
moves the reader to the attribute's value text node (or to an entity reference if the value contains one). After processing the attribute value, you must call Read()
to move to the next node.
Exceptions
Exception | Condition |
---|---|
InvalidOperationException | Called when the reader is not on an attribute node. |
Example
using System; using System.Xml; class Program { static void Main() { string xml = @"<book title='C# in Depth' author='Jon Skeet' />"; XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); XmlNodeReader reader = new XmlNodeReader(doc); // Move to theelement reader.Read(); // Move to the first attribute (title) if (reader.MoveToFirstAttribute()) { do { Console.WriteLine($"Attribute: {reader.Name}"); // Read the attribute value if (reader.ReadAttributeValue()) { Console.WriteLine($"Value: {reader.Value}"); } } while (reader.MoveToNextAttribute()); } reader.Close(); } }