Microsoft Docs

XmlNodeReader.EOF Property

Summary

Gets a value indicating whether the end of the stream has been reached.

Syntax

public override bool EOF { get; }

Returns

True if the reader is positioned after the last node of the XML document; otherwise, false.

Remarks

The EOF property is a read‑only boolean that becomes true when the reader has passed the last node in the underlying XML document. It is commonly used in a loop to determine when parsing should stop.

Example

The following example demonstrates how to use XmlNodeReader.EOF to iterate through an XML document.


// Sample XML
string xml = @"<books>
                <book id='1'>
                    <title>C# in Depth</title>
                </book>
                <book id='2'>
                    <title>ASP.NET Core</title>
                </book>
              </books>";

XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
XmlNodeReader reader = new XmlNodeReader(doc);

while (!reader.EOF)
{
    if (reader.NodeType == XmlNodeType.Element && reader.Name == "title")
    {
        Console.WriteLine(reader.ReadElementString());
    }
    else
    {
        reader.Read();
    }
}

See Also