Author: zhongnian_wei & 163.com)
Reading XML using dataset readxml alone is very efficient for small data volumes, but it is insufficient for XML with large data volumes.
For example, if you want dataset to read a 16 m XML file, you can wait for a long time. If the configuration of your machine is not high, it must be ugly and awkward.
You can't see it.
ASIDE: If XML comes from dataset, you are lucky. You can use dataset to bring the architecture information, so you don't have to worry about the expansion of a few K of data.
By default, readxml uses xmlreadmode. Auto to read data, which leaves an inefficient foreshadowing for large data volumes.
If XML does not have scheme, dataset will calculate the XML structure and load it again. This is the main cause of inefficiency.
Let the dataset estimate not let us help him calculate, because dataset already provides a readxmlschema method.
As follows:
Dim xmltext as string 'saves the XML text
Dim myds as new dataset
Dim mytab as datatable
'Load the architecture
Myds. readxmlschema (new IO. stringreader (xmltext ))
For each mytab in myds. Tables
Mytab. beginloaddata ()
Next
Then let dataset load the data.
Note: because the previous one helped him load the schema information, we can let dataset ignore the schema when loading data.
'Load data
Myds. readxml (new IO. stringreader (xmltext), xmlreadmode. ignoreschema)
For each mytab in myds. Tables
Mytab. endloaddata ()
Next
OK, so that the data is quickly loaded to dataset. After actual tests, the larger the data volume, the higher the efficiency ratio.
Generally, getxml is used to obtain dataset XML, which is indeed convenient. However, the returned results have erased the dataset schema information, and the rest is simple data.
Dataset also left us a writexml method (moving ing, do not disturb...). This method can write dataset data to a file or stream.
For example:
Dim MS as new IO. memorystream
Parameters following dataset. writexml (MS, xmlwritemode. writeschema) 'are critical, indicating that schema information is to be taken.
In this way, all data with dataset architecture information is saved in the MS stream.