```html XmlNode.Load Method (System.Xml) – .NET Framework

Microsoft Docs

XmlNode.Load Method

Namespace: System.Xml

Assembly: System.Xml.dll

Definition

public void Load(string filename);
public void Load(string filename, System.Xml.XmlReaderSettings settings);
public void Load(System.IO.Stream inStream);
public void Load(System.IO.Stream inStream, System.Xml.XmlReaderSettings settings);
public void Load(System.Xml.XmlReader reader);

Parameters

NameTypeDescription
filenamestringThe path to the XML file to load.
settingsXmlReaderSettingsOptional settings that control how the XML is read.
inStreamStreamA stream containing the XML data.
readerXmlReaderAn XmlReader positioned at the start of the node to load.

Returns

This method does not return a value. It populates the XmlNode with the contents of the specified XML source.

Remarks

The Load method replaces the current node and its children with the content from the specified XML source. If the node already has children, they are discarded.

When providing an XmlReaderSettings object, you can control aspects such as validation, whitespace handling, and DTD processing.

Exceptions

ExceptionCondition
ArgumentNullExceptionfilename, inStream, or reader is null.
XmlExceptionThe XML source is not well-formed.
IOExceptionThere is an I/O error while accessing the file or stream.
UnauthorizedAccessExceptionThe caller does not have the required permission.

Example

using System;
using System.Xml;

class Program
{
    static void Main()
    {
        XmlDocument doc = new XmlDocument();
        // Load XML from a file.
        doc.Load("books.xml");
        Console.WriteLine("Root element: " + doc.DocumentElement.Name);
    }
}
            

For a more detailed example, see XmlDocument.Load.

See Also

```