Conjecture about XML

Source: Internet
Author: User

What is XML? XML stands for meta-Markup Language (Media Markup Language), which provides a format for describing structured data. It is designed to store and transmit data.
XML is the summer of my sophomore year. So far, I have used it to store and transmit data. But when I think about it, the problem comes out: the data I store and transmit is very small, and at most 100 K for a single file. I can see that some blogs and forums mostly adopt XML technology, but I can't find out if I have a problem. Why are tens of thousands of users on each site? Isn't it very inconvenient to put everyone's data into an XML file for management? In addition, one's messages can grow infinitely. What if the data volume is very large? How can I display it on the page? I just thought that I wrote a program to write an XML file with 1 million records (less than 50 MB). Before I could think about it, a younger brother raised this question, because my recent project was developed based on my suggestions and the XML technology, he asked me what to do when the data volume increases infinitely.
After thinking about it for one day, I re-wrote the program to verify it and tried to write 1 million records in SQL Server. I found the problem was serious.
Use the following C # code to write an XML file with 1 million records, and then read a record from the 1 million data records.

Using system;
Using system. xml;

Public class xmldoc
{
[Stathread]
Public static void main (string [] ARGs)
{
System. datetime A = system. datetime. now;
Createxml ("myxml. xml ");
System. datetime B = system. datetime. now;
Console. writeline ("time used to write an XML file: {0}", B-);
A = system. datetime. now;
Console. writeline (readscore ("100 "));
B = system. datetime. now;
Console. writeline ("time used to read a record: {0}", B-);
}

// Read the specified record from the myxml. xml file
Public static int readscore (string student)
{
Int result = 0;
Xmldocument Doc = new xmldocument ();
Doc. Load ("myxml. xml ");
Xmlnode node = Doc. documentelement. selectsinglenode (string. Format ("Descendant: Student [@ name = '{0}']", student ));
If (node! = NULL ){
Result = int. parse (node. attributes ["score"]. value );
}
Return result;
}

// Create an XML file containing 1 million records
Public static void createxml (string filepath)
{
Xmltextwriter xtw = new xmltextwriter (filepath, null );
Xtw. Formatting = formatting. indented;
Xtw. indentation = 3;
Xtw. writestartdocument ();
Xtw. writecomment ("test XML support for massive data ");
Xtw. writestartelement ("Students ");
For (INT I = 0; I <= 1000000; I ++ ){
Xtw. writestartelement ("student ");
Xtw. writeattributestring ("name", I. tostring ());
Xtw. writeattributestring ("score", convert. tostring (I + 10 ));
Xtw. writeendelement ();
}
Xtw. writeendelement ();
Xtw. writeenddocument ();
Xtw. Flush ();
Xtw. Close ();
}
}

The running result is as follows:

The time difference between writing 1 million records and reading one record is so big!
Try writing the same 1 million records in SQL Server: declare @ I int
Set @ I = 0
While @ I <100000
Begin
Insert into student ([name], score) values (convert (char (8), @ I), @ I + 10)
Set @ I = @ I + 1
End

When data is written at 1 minute 22 seconds, a piece of data is read for 2 seconds.
XML standards are good, and accessing XML data with text files is definitely not as fast as database systems!
So what is going on with blogs and forums? Oh, forget that SQL Server supports XML.
After some settings (the help document of SQL Server is clear in specific steps), you can enter a URL in the IE address bar to read XML data, it is much faster than Directly Reading XML documents containing a large amount of data.
Websites such as blogs should be the functions supported by the application database for XML, reading specified data from the database and returning XML streams, then, use XSL to convert XML data to HTML pages that are easy to view. (This is purely a personal guess. If it is incorrect, please kindly advise)
The problem is solved in this way. Fortunately, we only use XML as a configuration file with little data. Otherwise, the entire architecture would be wrong. Khan!

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.