home *** CD-ROM | disk | FTP | other *** search
Wrap
<%@ Register TagPrefix="Acme" TagName="SourceRef" Src="/quickstart/util/SrcRef.aspx"%> <!-- #include virtual="/quickstart/howto/doc/xml/header.inc" --> <h4>How Do I...Infer DataSet mappings from XML?</h4> <div class="indent" style="width:660"> This sample illustrates how to create DataSet mappings from XML Data. Here we use the concept of inference whereby the structure of the XML data is used to build a relational schema. This is then used to create a relational structure of tables and columns to store data in a DataSet that conforms to the infered schema.</div> <h4>Infer DataSet mappings from XML</h4> <Acme:SourceRef ViewSource="/quickstart/howto/samples/Xml/DataSetMapXMLData/DataSetMapXMLData.src" RunSample="/quickstart/howto/samples/Xml/DataSetMapXMLData/DataSetMapXMLData.aspx" Icon = "/quickstart/images/genicon.gif" Caption="DataSetMapXMLData.aspx" runat="server" /> <br clear="left"><br> <div class="indent" style="width:660"> To achieve inference on the XML the <b>InferSchema</b> method is called with the XML file. </div> <div class="code"><xmp> // Infer the DataSet schema from the XML data dataset.InferSchema(new StreamReader("books.xml")); </xmp></div> <div class="indent" style="width:660"> As in the previous topic we use the DisplayTables() method to display the structure and contents of the DataSet. See <a href="/quickstart/howto/doc/Xml/LoadDataSetXMLData.aspx">How Do I...Load a DataSet with XML?</a></br> </div> <br clear="left"><div class="indent" style="width:660"> The output from the DisplayTables() method for the schema inferred from the <a target="_blank" href="/quickstart/util/srcctrlwin.aspx?path=/quickstart/howto/samples/Xml/DataSetMapXMLData/&file=books.xml">books.xml</a> file is illustrated below showing the table and column names and the row contents. </div> <div class="code"><xmp> Creating an XmlDataDocument ... Content of Tables ... TableName = book --------- Columns ... genre publicationdate ISBN title book_Id price Number of rows = 3 Rows ... autobiography 1981 1-861003-11-0 The Autobiography of Benjamin Franklin 0 8.99 novel 1967 0-201-63361-2 The Confidence Man 1 11.99 philosophy 1991 1-861001-57-6 The Gorgias 2 9.99 TableName = author --------- Columns ... first-name last-name book_Id Number of rows = 3 Rows ... Benjamin Franklin 0 Herman Melville 1 Sidas Plato 2 </xmp></div> <H4>Summary</H4> <OL> <LI>Inference is the mechanism whereby the structure of the XML data is used to build a relational schema. <LI>The DataSet InferSchema method builds relational mapping using the supplied XML file in a StreamReader. </LI></OL> <!-- #include virtual="/quickstart/howto/include/footer.inc" -->