XmlReader.ReadElementContentAsLong Method

Represents a node in the XML document that can be read as a System.Int64.

public long ReadElementContentAsLong()
public long ReadElementContentAsLong(XmlDictionaryReaderQuotas quotas)

This method reads the current node as a System.Int64. It is intended for elements that contain a primitive value.

Parameters

  • quotas XmlDictionaryReaderQuotas - An XmlDictionaryReaderQuotas object that contains the maximum limits for the values returned by the reader.

The first overload has no parameters.

Return Value

System.Int64 - The content of the element as a System.Int64.

Remarks

This method reads the content of an element. If the element contains mixed content or child elements, XmlException is thrown.

The reader must be positioned on an element node.

This method skips all leading whitespace characters.

If the value is not a valid System.Int64, an XmlException is thrown.

The maximum number of bytes to read from the value is controlled by the MaxBytesPerRead property of the XmlDictionaryReaderQuotas object passed to the second overload.

Exceptions

  • System.Xml.XmlException - The reader is not positioned on an element node, or the element contains mixed content or child elements, or the element's value cannot be parsed as a System.Int64.
  • System.InvalidOperationException - The reader is not positioned on an element node.

Example

C# Example

using System;
using System.Xml;

public class Example
{
    public static void Main(String[] args)
    {
        string xml = @"<root><longValue>123456789012345</longValue></root>";
        using (XmlReader reader = XmlReader.Create(new System.IO.StringReader(xml)))
        {
            while (reader.Read())
            {
                if (reader.IsStartElement() && reader.Name == "longValue")
                {
                    long value = reader.ReadElementContentAsLong();
                    Console.WriteLine("Element content as long: " + value);
                }
            }
        }
    }
}