Gets the number of attributes on the current node. : XmlTextReader « XML « C# / C Sharp






Gets the number of attributes on the current node.

 
using System;
using System.IO;
using System.Xml;

public class Sample {

  public static void Main() {

        string xmlData = 
        @"<book>
           <title>C#</title>
           <price>5.95</price>
          </book>";
    
        XmlTextReader reader = new XmlTextReader(new StringReader(xmlData));
    
          if (reader.HasAttributes)
          {
            Console.WriteLine("Attributes of <" + reader.Name + ">");
            for (int i = 0; i < reader.AttributeCount; i++)
            {
              reader.MoveToAttribute(i);
              Console.Write(" {0}={1}", reader.Name, reader.Value);
            }
            reader.MoveToElement(); //Moves the reader back to the element node.
          }
    
  }
}

   
  








Related examples in the same category

1.Create XmlTextReader with the specified string, XmlNodeType, and XmlParserContext.
2.Initializes a new instance of the XmlTextReader class with the specified file.
3.Create XmlTextReader with TextReader.
4.Gets the base URI of the current node.
5.Gets the depth of the current node in the XML document.
6.Gets the value of the attribute with the specified name.
7.Gets a value indicating whether the current node can have a Value other than String.Empty.
8.Gets a value indicating whether the current node is an empty element (for example, ).
9.Gets the current line position.
10.Gets the local name of the current node.
11.Moves to the first attribute.
12.Moves to the next attribute.
13.Gets the qualified name of the current node.
14.Gets or sets a value indicating whether to normalize white space and attribute values.
15.Parses the attribute value into one or more Text, EntityReference, or EndEntity nodes.
16.Decodes Base64 and returns the decoded binary bytes.
17.Reads the text contents of an element into a character buffer.
18.Resets the state of the reader to ReadState.Initial.
19.Gets or sets a value that specifies how white space is handled.
20.Gets the current xml:lang scope.
21.Sets the XmlResolver used for resolving DTD references.
22.Gets the current xml:space scope.