For XML, I think everyone knows it well. I don't need to bother to describe what it is. I think XML will surely shine in the future of Web development, XML is a scalable markup language, which allows enterprises to develop their own data formats, data is transmitted over the network according to this format and then converted into the desired format through XSLT, which easily solves the problem of incompatible data formats. For Internet data transmission, I think this is the most attractive place for our programmers!
Our topic today is not about the advantages of XML, but about how to use XML in C. Next, let's take a look at some basic theoretical knowledge about accessing XML using a program.
Two access models:
There are two models for accessing and then operating XML files in a program: DOM (Document Object Model) and stream model. The advantage of DOM is that it allows editing and updating XML documents, you can randomly access the data in the document and use XPath for query. However, the disadvantage of DOM is that it needs to load the entire document to the memory at a time. For large documents, this may cause resource problems. The stream model solves this problem well because it uses the stream concept to access XML files, that is, it only has the current node in the memory at any time, but it also has its shortcomings. It is read-only and only forward, and cannot perform backward navigation in the document. Although each has its own merits, we can also use the two in the program to complement each other! Today, we will mainly discuss XML reading. Let's discuss the stream model in detail!
Variations in the stream model:
The stream model iterates one node in the XML document each time. It is suitable for processing large documents and consumes less memory. The stream model has two variants: the "push" model and the "pull" model.
The push model is also commonly referred to as SAX. SAX is an event-driven model. That is to say, every time it discovers a node, it uses the push model to trigger an event, however, we must write the processing programs for these events, which is very inflexible and troublesome.
. NET uses the implementation scheme based on the "pull" model. When traversing a document, the "pull" model will pull the part of the document that is interested from the reader without triggering events, allow us to access documents in a programmatic manner, which greatly improves flexibility. In terms of performance, the "pull" model can be used to process nodes selectively. Every time a node is found in SAX, it notifies the client, the "pull" model can improve the overall efficiency of the Application. In. NET, the "pull" model is implemented as an XmlReader class. Let's take a look at the inheritance structure of this class:
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