XmlValidatingReader.ReadAttributeValue Method ()


Parses the attribute value into one or more Text, EntityReference, or EndEntity nodes.

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

override ReadAttributeValue : unit -> bool

Return Value

Type: System.Boolean

true if there are nodes to return.

false if the reader is not positioned on an attribute node when the initial call is made or if all the attribute values have been read.

An empty attribute, such as, misc="", returns true with a single node with a value of String.Empty.


The XmlValidatingReader class is obsolete in .NET Framework 2.0. You can create a validating XmlReader instance by using the XmlReaderSettings class and the Create method. For more information, see the Remarks section of the XmlReader reference page.

Use this method after calling MoveToAttribute to read through the text or entity reference nodes that make up the attribute value. The Depth of the attribute value nodes is one plus the depth of the attribute node. The Depth increments and decrements by one when you step into and out of general entity references.

For example, suppose you have the following XML: <test name="a &b; c"/>

where the entity b is defined in the document type definition (DTD) as follows: <!ENTITY b "123">

If EntityHandling is set to ExpandCharEntities, the following C# code returns the attribute value as two text nodes and one entity reference node:

  while (reader.ReadAttributeValue())
  if (reader.NodeType == XmlNodeType.Text)
  // at this point reader.Value == "a " or " c"
  else if (reader.NodeType == XmlNodeType.EntityReference)
  // at this point reader.Name == "b"
  while (reader.ReadAttributeValue() &&
  reader.NodeType != XmlNodeType.EndEntity)
  // reader.Value == "123"

The following example reads an attribute with text and entity reference nodes.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top