Describes two XML file action classes

Source: Internet
Author: User
Tags xml parser

describes two XML file action classes

Extensible Markup Language XML (Extend Mark Language) is a language that describes data and structure, and XML data can be saved in any document that can store text. HTML is used to describe skins, and XML was designed to represent the original information and completely ignore the presentation of the data from the outset. XML is powerful because the computer industry has made XML the standard for data exchange and has provided a significant number of support tools.
It is believed that the most exciting application of XML is the encapsulation Format (SOAP message) that can be delivered as a message in a distributed application, most commonly saved as an application's setup option.
This article implements a Cxmlfile class to manipulate XML files, provides special interface support for saving application settings options, and implements a Cpersistenttreectrl (a tree control that can hold tabs) to demonstrate the use of cxmlfile classes.
C + + XML parser, the most famous I am afraid to be the number of open source xerces-c++ and xml4c.
Xerces-c++ is the development effort of the Apache team, which adheres to the DOM and sax specifications, provides good usability and cross-platform features, and guarantees high execution efficiency, and has been the preferred XML parser for many foreign projects. But it is not good for Chinese compatibility, in the processing of XML content with the characters, often errors, this is the Chinese C + + programmers, is unforgivable fatal flaw.
XML4C is an XML parser developed by IBM on the basis of xerces-c++. It has exactly the same calling interface as Xerces-c++, and it supports more text encoding. The text encoding supported by XML4C is 10 times times or even 20 times times more than xerces-c++. But because XML4C is developed on the basis of xerces-c++, it has the same problem with the compatibility of Chinese XML document content.
  Mr. Ming in Developerworks China website: xml: All articles: "Analysis of XML4C source code, perfect compatibility with Chinese XML" proposed a simple solution to solve the Chinese character compatibility part of the problem: so that xml4c can support Chinese node values, However, the node name or attribute value is still not supported in Chinese. (This is the result of last year's test, I don't know if there is a complete solution now, estimated to rewrite the XMLString class and String functions, there are a number of related things, the author considered a moment, did not try to change, in case the change is good, the enemy again out of a new version, it will not be zoned, hehe. We found that the MSXML SDK perfectly supports Chinese, and the program interface is similar to XML4C, Xerces-c++, where the MSXML SDK is used in general applications. The Cxmlfile class is used to save program setting values, usually using only member functions that are not related to the XML interpreter.

Gets the node value (Long integer) long getlong (const char* cstrbasekeyname, const char* cstrvaluename, long Ldefaultvalue);

Sets the node value (Long integer) long setlong (const char* cstrbasekeyname, const char* cstrvaluename, long LValue); 
                      Gets the node value (string) std::string GetString (const char* cstrbasekeyname, const char* Cstrvaluename,
Const char* Cstrdefaultvalue);

Set node value (string) long setstring (const char* cstrbasekeyname, const char* cstrvaluename, const char* cstrvalue); Get Node Properties std::string getattribute (const char* cstrbasekeyname, const char* cstrvaluename, const char* CST
Rattributename, const char* cstrdefaultattributevalue); Set node properties long setattribute (const char* cstrbasekeyname, const char* cstrvaluename, const char* cstrattributename, const

char* cstrattributevalue); Get node value long getnodevalue (const char* cstrbasekeyname, const char* cstrvaluename, const char* Cstrdefaultvalue, STD::STR ing& strvalue, const char* cstrattributename, const char* CSTRDEFAUltattributevalue,std::string& strattributevalue); Set node value long setnodevalue (const char* cstrbasekeyname, const char* cstrvaluename, const char* cstrvalue=null, const char

* Cstrattributename=null, const char* cstrattributevalue=null);

Deletes a node and all its child nodes long deletesetting (const char* cstrbasekeyname, const char* cstrvaluename); Gets the key value of a node's child node long getkeysvalue (const char* cstrbasekeyname, std::map<std::string, std::string>& keys_val)

;

Gets the key name of a node's child node long getkeys (const char* cstrbasekeyname, std::vector<std::string>& keys);
Save the XML file bool Save (const char* filename=null);

Load XML file bool Load (const char* filename, const char* root_name= "XmlRoot");
change void Discardchanges () without saving;
 Empty content void clear ();

A simple example of writing and saving:

Cxmlfile XmlFile;
Xmlfile.load ("File.xml");
Xmlfile.setlong ("student/Situation", "age",);
Xmlfile.setstring ("Student/Condition", "Native Place", "Zhejiang Shengzhou");
Xmlfile.setstring ("Student/Condition", "gender", "male");
Xmlfile.save ();

A simple example of reading:

Cxmlfile XmlFile;
Xmlfile.load ("File.xml");
Long age= xmlfile.getlong ("student/condition", "age",
std::string strhomeplace =xmlfile.getstring ("Student/Condition", "Native Place", "Zhejiang Shengzhou");
std::string strsex =xmlfile. GetString ("Student/Condition", "gender", "male");

The Cpersistenttreectrl class has two main member functions:

Load from a XML file
bool Load (const char* filename, const char* tree_name= "Treename", bool bimage=false);
Save to a XML file
bool Save (const char* filename, const char* tree_name= "Treename", bool bimage=false);

To save and load the nodes of the tree, the efficiency of the access may not be high, the right to demonstrate it.

Note: Win2K with Msxml3.0,winxp MSXML4.0, should be guaranteed to install MSXML on the target computer.

Download source code

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.