Export (0) Print
Expand All

XmlTextReader.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)

Public Overrides Function ReadAttributeValue As Boolean

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.


Starting with the .NET Framework 2.0, we recommend that you create XmlReader instances by using the XmlReader.Create method to take advantage of new functionality.

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; it increments and decrements by one when you step into and out of general entity references.

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

Imports System
Imports System.IO
Imports System.Xml

public class Sample

  public shared sub Main()

    Dim reader as XmlTextReader = nothing

       'Create the XML fragment to be parsed. 
       Dim xmlFrag as string ="<book genre='novel' misc='sale-item &h; 1987'></book>" 

       'Create the XmlParserContext. 
       Dim context as XmlParserContext 
       Dim subset as string = "<!ENTITY h 'hardcover'>"
       context = new XmlParserContext(nothing, nothing, "book", nothing, nothing, subset, "", "", XmlSpace.None)

       'Create the reader.
       reader = new XmlTextReader(xmlFrag, XmlNodeType.Element, context)

       'Read the misc attribute. The attribute is parsed 
       'into multiple text and entity reference nodes.
       while (reader.ReadAttributeValue())
          if (reader.NodeType = XmlNodeType.EntityReference)
            Console.WriteLine("{0} {1}", reader.NodeType, reader.Name)
             Console.WriteLine("{0} {1}", reader.NodeType, reader.Value)
          end if
        end while

       if Not reader Is Nothing
      End if
      end try
  end sub
end class 

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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.

© 2014 Microsoft