System.Xml.XmlDataDocument.Load Method

Loads the XmlDataDocument from the specified System.Xml.XmlReader.

Syntax

public override void Load (XmlReader reader)

Parameters

reader
The XmlReader containing the XML document to load.

Remarks

XmlDataDocument does not support creating entity references. If the data source contains entity references, you must create an System.Xml.XmlValidatingReader with the XmlValidatingReader.EntityHandling property set to EntityHandling.ExpandEntities (this is the default behavior) and pass the XmlValidatingReader to the Load method. If you do not use an XmlValidatingReader, the Load method throws an exception.

The Load method always preserves significant white space. The XmlDocument.PreserveWhitespace property determines whether or not white space is preserved. The default is false, white space is not preserved.

If the reader is in the initial state (that is, ReadState=ReadState.Initial), Load consumes the entire contents of the reader and builds the DOM from what it finds.

If the reader is already positioned on some node at depth "n", then this method loads that node and all subsequent siblings up to the end tag that closes depth "n". This has the following results.

If the current node and its following siblings look similar to the following:

Example

<!--comment--><element1>one</element1><element2>two</element2>

Load throws an exception, because a document cannot have two root-level elements. If the current node and its following siblings look similar to the following:

Example

<!--comment--><?process
    instruction?><!--comment--></endtag>

Load will succeed; however, you will have an incomplete DOM tree, because there is no root-level element. You have to add a root-level element before you save the document; otherwise, the XmlDocument.Save(string) method throws an exception.

If the reader is positioned on a leaf node that is invalid for the root level of a document (for example, a white space or attribute node), the reader continues to read until it is positioned on a node that can be used for the root. The document begins loading at this point.

Requirements

Namespace: System.Xml
Assembly: System.Data (in System.Data.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0