How to load XML data to xmldatadocument
This example illustrates how to load XML into the xmldatadocument class. This class extends the xmldocument class and allows you to store, retrieve, and operate structured data through the dataset class (which provides a link view on the loaded XML data. The dependency between the xmldocument class and the dataset class allows the component to mix the XML and the data source's relational views unrelated to the same basic data. As detailed in other topics, there are differences between these views. It is worth noting that you cannot access XML data not mapped to the relational view through relational objects (such as tables and rows. However, you can easily move from a link row to the corresponding XML element to access the XML data.
You can use xmldatadocument anywhere where xmldocument is used; all topics that describe xmldocument can also be applied to xmldatadocument. Therefore, the information contained in the following topics is also related to xmldatadocument:
- How to load and use xmldocument
- How to Use xmldocument to save XML
There is also a corresponding topic on how to read XML data from xmldatadocument. This topic mainly describes how to read XML only using xmldatadocument.
In addition, the topic uses the XML and dataset classes to provide additional information about how to use xmldatadocument and dataset.
|
[Running example] | [View Source code] |
See the followingCodeAs shown in, this example only loads the XML data in the example file books. XML to xmldatadocument and displays the data on the screen.
public class loadxmldocumentsample {private const string document = "books. XML "; public static void main () {loadxmldocumentsample myloadxmldocumentsample = new loadxmldocumentsample (); myloadxmldocumentsample. run (document);} public void run (string ARGs) {try {// load the XML from file console. writeline (); console. writeline ("loading file {0 }... ", argS); xmldatadocument myxmldocument = new xmldatadocument (); myxmldocument. load (ARGs); console. writeline ("xmldatadocument loaded with XML data successfully... ");} catch (exception e) {console. writeline ("exception: {0}", E. tostring () ;}}
public class loadxmldocumentsample private const document as string = "books. XML "public shared sub main () dim myloadxmldocumentsample as loadxmldocumentsample myloadxmldocumentsample = new loadxmldocumentsample () myloadxmldocumentsample. run (document) end sub public sub run (ARGs as string) Try 'Load the XML from file console. writeline () console. writeline ("loading file {0 }... ", argS) dim myxmldocument as xmldatadocument = new xmldatadocument () myxmldocument. load (ARGs) console. writeline ("xmldatadocument loaded with XML data successfully... ") catch e as exception console. writeline ("exception: {0}", E. tostring () end try end sub end class
|
C # |
VB |
|
Summary
- The xmldatadocument class provides memory cache for XML data.
- Xmldatadocument extends the xmldocument class. Xmldatadocument can be used anywhere in the xmldocument class.
- Xmldatadocument and dataset classes are closely related. In fact, xmldatadocument can be considered as an xmldocument for dataset recognition.