XML and relational data -- save the dataset as XML

Source: Internet
Author: User
How to save a dataset as XML

This example illustrates how to use xmldatadocument to save the relational data in the dataset to an XML file. It indicates the conversion from Relational Data to XML data.

 

VB savedatasetxmldata. aspx

[Running example] | [View Source Code]

How to save the dataset ing to the subject of the XSD Schema file has generated a relational table for the dataset; now, this example saves these tables as XML data. This is a process of generating and verifying the Hierarchical XML based on the internal XML Schema Definition Language (XSD) architecture.

As shown in the following code, this example first creates the xmldatadocument of the dataset.


// Load the DataSet with relation data            DataSet dataset = new DataSet();            LoadDataSet(dataset);            // Create an XmlDataDocument for the DataSet            XmlDataDocument datadoc = new XmlDataDocument(dataset);            
' Load the DataSet with relation data            Dim dataset As New DataSet            LoadDataSet(dataset)            ' Create an XmlDataDocument for the DataSet            Dim datadoc As XmlDataDocument = New XmlDataDocument(dataset)            
C # VB  

This example uses the loaddataset function to create a dataset. To ensure that the dataset is correctly loaded, this example displays the dataset on the screen. Then, this example uses the writexmlschema method of dataset to write the schema created by dataset. To output dataset content as XML, this example uses the file name to call the writexml method of the dataset. Then, this example reads the newly written XML and displays the data on the screen.

// Load the DataSet with relation data            DataSet myDataSet = new DataSet();            LoadDataSet(myDataSet);            DisplayTables(myDataSet);            // Write out schema representation            myDataSet.WriteXmlSchema(m_SchemaFile);            // Write out XML data form relational data            myDataSet.WriteXml(m_XmlFile, XmlWriteMode.IgnoreSchema);            // Create an XmlDataDocument for the DataSet            XmlDataDocument datadoc = new XmlDataDocument(myDataSet);            // Display the XML            DisplayXMLData(datadoc);            
    'Load the DataSet with relation data            Dim myDataSet as DataSet = new DataSet()            LoadDataSet(myDataSet)            DisplayTables(myDataSet)            'Write out schema representation            myDataSet.WriteXmlSchema(m_SchemaFile)            'Write out XML data form relational data            myDataSet.WriteXml(m_XmlFile, XmlWriteMode.IgnoreSchema)            'Create an XmlDataDocument for the DataSet            Dim datadoc as XmlDataDocument = new System.Xml.XmlDataDocument(myDataSet)            'Display the XML            DisplayXMLData(datadoc)            
C # VB  

This example writes XML data to the file personpet. xml. Now, you can use xmlreader to read the XML data in xmldatadocument and display the data to display the XML of the relational data. For more information about reading XML documents, see how to read XML from xmldatadocument.

Summary
  1. Xmldatadocument can be constructed from dataset. It provides XML APIs for relational data.
  2. By using the XML method of xmldatadocument, you can access the data input through the dataset relational method.
  3. You can use the writexml method of dataset or the Save method of xmldatadocument to save XML data. The former stores the standardized view of data mapped through the relationship, while the latter stores completely real XML. If you only input data through dataset, these methods are equivalent.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.