XmlDataDocument.GetRowFromElement(XmlElement) Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Recupera l'oggetto DataRow associato all'oggetto XmlElement specificato.
public:
System::Data::DataRow ^ GetRowFromElement(System::Xml::XmlElement ^ e);
public System.Data.DataRow? GetRowFromElement (System.Xml.XmlElement? e);
public System.Data.DataRow GetRowFromElement (System.Xml.XmlElement e);
member this.GetRowFromElement : System.Xml.XmlElement -> System.Data.DataRow
Public Function GetRowFromElement (e As XmlElement) As DataRow
Parametri
Oggetto XmlElement di cui si desidera recuperare l'elemento DataRow associato.
Restituisce
DataRow contenente una rappresentazione di XmlElement. null se non vi è alcun DataRow associato a XmlElement.
Esempio
Nell'esempio seguente viene modificato il prezzo del primo libro.
#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 = gcnew 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( safe_cast<XmlElement^>(root->FirstChild) );
row["price"] = "12.95";
Console::WriteLine( "Display the modified XML data..." );
Console::WriteLine( doc->DocumentElement->OuterXml );
}
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
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
Nell'esempio vengono usati i file di input seguenti:
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>