Freigeben über


XmlDataDocument.DataSet-Eigenschaft

Ruft ein DataSet ab, das eine relationale Darstellung der Daten im XmlDataDocument bereitstellt.

Namespace: System.Xml
Assembly: System.Data (in system.data.dll)

Syntax

'Declaration
Public ReadOnly Property DataSet As DataSet
'Usage
Dim instance As XmlDataDocument
Dim value As DataSet

value = instance.DataSet
public DataSet DataSet { get; }
public:
property DataSet^ DataSet {
    DataSet^ get ();
}
/** @property */
public DataSet get_DataSet ()
public function get DataSet () : DataSet

Eigenschaftenwert

Ein DataSet, das verwendet werden kann, um mithilfe eines relationalen Modells auf die Daten im XmlDataDocument zuzugreifen.

Hinweise

Mit dem DataSet können Sie auf die Daten im XmlDataDocument unter Verwendung eines relationalen Modells zugreifen. Dies bedeutet, dass Sie die Daten als Tabellen und Ansichten, Zeilen und Spalten, Beziehungen usw. behandeln können. Am DataSet vorgenommene Änderungen werden sofort im XmlDataDocument angezeigt.

Beispiel

Im folgenden Beispiel wird der Preis eines Buches mithilfe der DataSet-Methoden geändert.

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.
    doc.DataSet.ReadXmlSchema("store.xsd") 
 
    'Load the XML data.
    doc.Load("2books.xml")

    'Change the price on the first book using 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...")
    doc.Save(Console.Out)

  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.
     doc.DataSet.ReadXmlSchema("store.xsd"); 

     //Load the XML data.
     doc.Load("2books.xml");

     //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...");
     doc.Save(Console.Out);
  }
} // End class
#using <System.dll>
#using <System.Xml.dll>
#using <System.Data.dll>

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

int main()
{
   
   //Create an XmlDataDocument.
   XmlDataDocument^ doc = gcnew XmlDataDocument;
   
   //Load the schema file.
   doc->DataSet->ReadXmlSchema( "store.xsd" );
   
   //Load the XML data.
   doc->Load( "2books.xml" );
   
   //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..." );
   doc->Save( Console::Out );
}
import System.*;
import System.Data.*;
import System.Xml.*;

public class Sample
{
    public static void main(String[] args)
    {
        //Create an XmlDataDocument.
        XmlDataDocument doc = new XmlDataDocument();

        //Load the schema file.
        doc.get_DataSet().ReadXmlSchema("store.xsd");

        //Load the XML data.
        doc.Load("2books.xml");

        //Update the price on the first book using the DataSet methods.
        DataTable books = doc.get_DataSet().get_Tables().get_Item("book");
        books.get_Rows().get_Item(0).set_Item("price", "12.95");

        Console.WriteLine("Display the modified XML data...");
        doc.Save(Console.get_Out());
    } //main
} //Sample // End class

Im Beispiel werden die folgenden beiden Dateien als Eingabe verwendet.

2books.xml

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

store.xsd

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

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

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

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

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

</xsd:schema>

Plattformen

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

XmlDataDocument-Klasse
XmlDataDocument-Member
System.Xml-Namespace
DataSet
DataTable