Introduction to XML parsing and xerces-c++ simple use examples __c++

Source: Internet
Author: User
Tags win32

XML is a meta language defined by the World Wideweb Federation (the World Consortium). It has become a general data Interchange format, its platform independence, language independence, System independence, to the data integration and interaction has brought great convenience. XML is interpreted in the same way in different languages, except that the syntax of the implementation is different.

XML itself is simply a format for encoding data in plain text, to take advantage of XML, or to take advantage of the data encoded in an XML file, you must first parse the data from plain text, so you must have a parser that recognizes the information in the XML document to interpret the XML document and extract the data from it. However, according to the different needs of data extraction, there are many analytic methods, different analytical methods have their own advantages and disadvantages and applicable environment. Selecting the appropriate XML parsing technology can effectively improve the overall performance of the application system.

All XML processing starts with parsing, whether using XSLT or the Java language, the first step is to read XML files, decode structures and retrieve information, and so on, which is parsing, which translates an unstructured sequence of characters representing an XML document into a structured component that satisfies the XML syntax.

There are two main types of parsing XML: SAX (simple APIs for XML) and Dom (Document ObjectModel).

Sax is based on the parsing of event streams. The advantages of Sax processing are very similar to the advantages of streaming media. Analysis can begin immediately, rather than wait for all data to be processed. Also, because an application checks data only when it reads data, it does not need to store the data in memory. This is a great advantage for large documents. In fact, an application doesn't even have to parse the entire document, and it can stop parsing when a condition is satisfied. In general, Sax is also much faster than its replacement dom. The SAX parser employs an event-based model that triggers a series of events when parsing an XML document, and when a given tag is found, it can activate a callback method that tells the method that the label has been found. Sax typically requires less memory because it lets developers decide which tag to process. Especially when developers only need to work with some of the data contained in the document, Sax has a better ability to expand. But coding is difficult when using a SAX parser, and it is difficult to access multiple different data in the same document at the same time. Advantages: (1), do not need to wait for all data to be processed, analysis can start immediately; (2), only when reading data to check the data, do not need to save in memory, (3), can be satisfied when a certain condition to stop parsing, do not have to parse the entire document, (4), efficiency and performance is higher, can resolve larger than the system memory documents. Disadvantages: (1), the need for the application of their own tag processing logic (such as maintenance parent/child relationship, etc.), the more complex the document the more complex the program, (2), one-way navigation, cannot locate the document hierarchy, it is difficult to access different parts of the same document data, do not support XPath

DOM is the official consortium standard for representing XML documents in a platform-and language-independent way. A DOM is a collection of nodes or pieces of information organized in a hierarchical hierarchy. This hierarchy allows developers to find specific information in the tree. Parsing the structure usually requires loading the entire document and the construction hierarchy before any work can be done. Because it is based on the information hierarchy, the DOM is considered to be tree based or object-based. Advantages: (1), allows applications to make changes to data and structure, (2), access is two-way, can be in the tree at any time to navigate up and down, get and manipulate any part of the data. Disadvantage: It is often necessary to load the entire XML document to construct the hierarchy, consuming resources.

The XML parsing library based on C + + language includes:

(1), expat:http://www.libexpat.org/;

(2), die-xml:https://code.google.com/p/die-xml/;

(3), xerces-c++:http://xerces.apache.org/xerces-c/index.html;

(4), tinyxml:http://www.grinninglizard.com/tinyxml/;

Compilation and use of xerces-c++:

1, from the http://xerces.apache.org/xerces-c/download.cgi#verify download Xerces-c-3.1.1.zip source code, and decompression;

2, with vs2010 open Xerces-c-3.1.1\projects\win32\vc10\xerces-all directory of Xerces-all.sln;

3, select SolutionConfigurations, Solution platforms respectively, and then select Solution ' Xerces-all ',--> Right-click, select Execute Rebuild Solution, will be in/ BUILD/WIN32/VC10 directory to generate the corresponding dynamic libraries and static libraries, where the static Debug/xerces-c_static_3d.lib and the statics release/xerces-c_static_3.lib to test 4, in the ' Xerces-all ' working space based on a new Testxerces project, selected this project, respectively, in the debug and release, engineering properties (1), Configuration properties--> Character set:use Unicode Character Set; (2), c/c++-->general-->additional Include directories:.. /.. /.. /.. /.. /SRC, C + +-->prerocessor add:

[HTML] view plain copy _crt_secure_no_deprecate _windows xerces_static_library xerces_building_library X Erces_use_transcoder_windows xerces_use_msgloader_inmemory Xerces_use_netaccessor_winsock XERCES_USE_FILEMGR_ WINDOWS xerces_use_mutexmgr_windows xerces_path_delimiter_backslash have_stricmp have_strnicmp HAVE_LIMITS_H H Ave_sys_timeb_h have_ftime have_wcsupr have_wcslwr have_wcsicmp have_wcsnicmp
StdAfx.h:

[CPP] view plain copy #pragma once #include "targetver.h" #include <stdio.h> #include XERC Esc/util/platformutils.hpp "#include" xercesc/util/xmlstring.hpp "#include" xercesc/dom/dom.hpp "#include" xercesc/u Til/outofmemoryexception.hpp "#include" xercesc/util/transservice.hpp "#include" xercesc/parsers/saxparser.hpp "#in Clude "xercesc/sax/handlerbase.hpp" #include "xercesc/framework/xmlformatter.hpp"
Stdafx.cpp:

[CPP]   View plain copy #include   "stdafx.h"      // todo:  reference any additional headers you need in stdafx. h  // and not in this file   #ifdef  _DEBUG  

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.