System.Xml.XmlValidatingReader.ReadAttributeValue Method

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

Syntax

public override bool ReadAttributeValue ()

Returns

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.

Remarks

Note:

The System.Xml.XmlValidatingReader class is obsolete in dnprdnext. You can create a validating System.Xml.XmlReader instance by using the System.Xml.XmlReaderSettings class and the erload:System.Xml.XmlReader.Create method. For more information, see Validating XML Data with XmlReader.

Use this method after calling XmlValidatingReader.MoveToAttribute(string) to read through the text or entity reference nodes that make up the attribute value. The XmlReader.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 XmlValidatingReader.EntityHandling is set to ExpandCharEntities, the following C# code returns the attribute value as two text nodes and one entity reference node:

Example

reader.MoveToAttribute("name");
  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"
  reader.ResolveEntity();
  while (reader.ReadAttributeValue() &&
  reader.NodeType != XmlNodeType.EndEntity)
  {
  // reader.Value == "123"
  }
  }
    }

Requirements

Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0