The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

XmlDataDocument.Load Method

Loads the XmlDataDocument using the specified data source and synchronizes the DataSet with the loaded data.

Note   In order to view the XML data relationally, you must first specify a schema to use for data mapping. This can be done either by calling the ReadXmlSchema method, or by creating the tables and columns within the DataSet manually. This step must be done before calling Load.

XmlDataDocument does not support creating entity references. If the data includes entity references, the Load method resolves and expands any entity references. However, if you are using the Load overload that takes an XmlReader as an argument, you must specify an XmlReader that can resolve entities.

Overload List

Loads the XmlDataDocument from the specified stream.

[Visual Basic] Overloads Overrides Public Sub Load(Stream)
[C#] public override void Load(Stream);
[C++] public: void Load(Stream*);
[JScript] public override function Load(Stream);

Loads the XmlDataDocument using the specified URL.

[Visual Basic] Overloads Overrides Public Sub Load(String)
[C#] public override void Load(string);
[C++] public: void Load(String*);
[JScript] public override function Load(String);

Loads the XmlDataDocument from the specified TextReader.

[Visual Basic] Overloads Overrides Public Sub Load(TextReader)
[C#] public override void Load(TextReader);
[C++] public: void Load(TextReader*);
[JScript] public override function Load(TextReader);

Loads the XmlDataDocument from the specified XmlReader.

[Visual Basic] Overloads Overrides Public Sub Load(XmlReader)
[C#] public override void Load(XmlReader);
[C++] public: void Load(XmlReader*);
[JScript] public override function Load(XmlReader);


[Visual Basic, C#, C++] The following example modifies the price of a book using the DataSet methods.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of Load. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Imports System
Imports System.Data
Imports System.Xml

public class Sample

  public shared sub Main()

      'Create an XmlDataDocument.
      Dim doc as XmlDataDocument = new XmlDataDocument()

      'Load the schema.
      'Load the XML data.
      Dim reader as XmlTextReader = new XmlTextReader("2books.xml")
      reader.MoveToContent() 'Moves the reader to the root node.
     'Change the price on the first book imports the DataSet methods.
     Dim books as DataTable = doc.DataSet.Tables.Item("book")
     books.Rows.Item(0).Item("price") = "12.95"
     Console.WriteLine("Display the modified XML data...")

  end sub
end class

using System;
using System.Data;
using System.Xml;
public class Sample {
    public static void Main() {
        // Create an XmlDataDocument.
        XmlDataDocument doc = new XmlDataDocument();
        // Load the schema file.
        // Load the XML data.
        XmlTextReader reader = new XmlTextReader("2books.xml");
        reader.MoveToContent(); // Moves the reader to the root node.
        // Update the price on the first book using the DataSet methods.
        DataTable books = doc.DataSet.Tables["book"];
        books.Rows[0]["price"] = "12.95";
        Console.WriteLine("Display the modified XML data...");
} // End class

#using <mscorlib.dll>
#using <System.dll>
#using <System.Data.dll>
#using <System.Xml.dll>

using namespace System;
using namespace System::Data;
using namespace System::Xml;

int main() 
   // Create an XmlDataDocument.
   XmlDataDocument* doc = new XmlDataDocument();

   // Load the schema file.

   // Load the XML data.
   XmlTextReader* reader = new XmlTextReader(S"2books.xml");
   reader->MoveToContent(); // Moves the reader to the root node.

   // Update the price on the first book using the DataSet methods.
   DataTable* books = doc->DataSet->Tables->get_Item( S"book" );
   books->Rows->get_Item(0)->set_Item(S"price", S"12.95");

   Console::WriteLine( S"Display the modified XML data...");

[Visual Basic, C#, C++] The example uses the following two input files.

[Visual Basic, C#, C++] 2books.xml

<!--sample XML fragment-->
  <book genre='novel' ISBN='10-861003-324'>
    <title>The Handmaid's Tale</title>
  <book genre='novel' ISBN='1-861001-57-5'>
    <title>Pride And Prejudice</title>

[Visual Basic, C#, C++] store.xsd

<xsd:schema xmlns:xsd="">

 <xsd:element name="bookstore" type="bookstoreType"/>

 <xsd:complexType name="bookstoreType">
  <xsd:sequence maxOccurs="unbounded">
   <xsd:element name="book"  type="bookType"/>

 <xsd:complexType name="bookType">
   <xsd:element name="title" type="xsd:string"/>
   <xsd:element name="author" type="authorName"/>
   <xsd:element name="price"  type="xsd:decimal"/>
  <xsd:attribute name="genre" type="xsd:string"/>

 <xsd:complexType name="authorName">
   <xsd:element name="first-name"  type="xsd:string"/>
   <xsd:element name="last-name" type="xsd:string"/>


[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

XmlDataDocument Class | XmlDataDocument Members | System.Xml Namespace

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft