XmlDataDocument.GetRowFromElement Method (XmlElement)


Retrieves the DataRow associated with the specified XmlElement.

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

Public Function GetRowFromElement (
	e As XmlElement
) As DataRow


Type: System.Xml.XmlElement

The XmlElement whose associated DataRow you want to retrieve.

Return Value

Type: System.Data.DataRow

The DataRow containing a representation of the XmlElement; null if there is no DataRow associated with the XmlElement.

The following example modifies the price of the first book.

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

The example uses the following input files:


<!--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>


<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: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"/>


.NET Framework
Available since 1.1
Return to top