This documentation is archived and is not being maintained.

XmlDataDocument.GetRowFromElement Method

Retrieves the DataRow associated with the specified XmlElement.

[Visual Basic]
Public Function GetRowFromElement( _
   ByVal e As XmlElement _
) As DataRow
public DataRow GetRowFromElement(
 XmlElement e
public: DataRow* GetRowFromElement(
 XmlElement* e
public function GetRowFromElement(
   e : XmlElement
) : DataRow;


The XmlElement whose associated DataRow you wish to retrieve.

Return Value

The DataRow containing a representation of the XmlElement; a null reference (Nothing in Visual Basic) if there is no DataRow associated with the XmlElement.


[Visual Basic, C#, C++] The following example modifies the price of the first book.

[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.
      'Change the price on the first book.
      Dim book as XmlElement 
      book = CType(doc.DocumentElement.FirstChild, XmlElement)
      Dim row as DataRow 
      row = doc.GetRowFromElement(book)
      row.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.
        //Change the price on the first book.
        XmlElement root = doc.DocumentElement;
        DataRow row = doc.GetRowFromElement((XmlElement)root.FirstChild);
        row["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.

   //Change the price on the first book.
   XmlElement* root = doc->DocumentElement;
   DataRow* row = doc->GetRowFromElement(__try_cast<XmlElement*>( root->FirstChild ));
   row->set_Item( S"price", S"12.95" );

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

[Visual Basic, C#, C++] The example uses the following 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.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

XmlDataDocument Class | XmlDataDocument Members | System.Xml Namespace