次の方法で共有


XmlDataDocument.GetRowFromElement メソッド

指定した XmlElement に関連付けられている DataRow を取得します。

Public Function GetRowFromElement( _
   ByVal e As XmlElement _) As DataRow
[C#]
public DataRow GetRowFromElement(XmlElemente);
[C++]
public: DataRow* GetRowFromElement(XmlElement* e);
[JScript]
public function GetRowFromElement(
   e : XmlElement) : DataRow;

パラメータ

  • e
    取得する対象の、関連付けられた DataRow を持つ XmlElement

戻り値

XmlElement の表現を格納している DataRowXmlElement に関連付けられた DataRow がない場合は null 参照 (Visual Basic では Nothing) 。

使用例

[Visual Basic, C#, C++] 最初の書籍の価格を変更する例を次に示します。

 
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.
      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...")
     Console.WriteLine(doc.DocumentElement.OuterXml)

  end sub
end class

[C#] 
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");
        
        //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...");
        Console.WriteLine(doc.DocumentElement.OuterXml);
    }
} // End class

[C++] 
#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.
   doc->DataSet->ReadXmlSchema(S"store.xsd");

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

   //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...");
   Console::WriteLine(doc->DocumentElement->OuterXml);
}

[Visual Basic, C#, C++] この例では、次の入力ファイルを使用します。

[Visual Basic, C#, C++] 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>

[Visual Basic, C#, C++] 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>

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

XmlDataDocument クラス | XmlDataDocument メンバ | System.Xml 名前空間