Use dataset. readxml to speed up reading XML without scheme ..

Source: Internet
Author: User
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.

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.