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
| Name | Type | Description |
|---|---|---|
| filename | string | The path to the XML file to load. |
| settings | XmlReaderSettings | Optional settings that control how the XML is read. |
| inStream | Stream | A stream containing the XML data. |
| reader | XmlReader | An 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
| Exception | Condition |
|---|---|
ArgumentNullException | filename, inStream, or reader is null. |
XmlException | The XML source is not well-formed. |
IOException | There is an I/O error while accessing the file or stream. |
UnauthorizedAccessException | The 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.