MFC Learning Notes XML file Operation class __mfc

Source: Internet
Author: User

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.

Get the value of the node (Long Integer)

Long Getlong (const char* cstrbasekeyname,const char* cstrvaluename, long Ldefaultvalue);

Set node value (Long integer)

Long Setlong (const char* cstrbasekeyname,const char* cstrvaluename, long LValue);

Get 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* Cstrattributename,const char* cstrdefaultattributevalue);

Set node properties

Long setattribute (const char*cstrbasekeyname, const char* Cstrvaluename,

constchar* cstrattributename, const char* cstrattributevalue);

Get node value

Long Getnodevalue (const char*cstrbasekeyname, const char* Cstrvaluename,

constchar* Cstrdefaultvalue, std::string& strvalue, const char*cstrattributename,

constchar* cstrdefaultattributevalue,std::string& Strattributevalue);

Set node values

Long setNodeValue (const char*cstrbasekeyname, const char* Cstrvaluename,

constchar* cstrvalue=null, const char* Cstrattributename=null,

constchar* cstrattributevalue=null);

Delete 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&keys_val);

Gets the key name of the child node of a node

Long Getkeys (const char* Cstrbasekeyname,

Std::vector&keys);

Save XML file

BOOL Save (const char* filename=null);

Loading XML files

BOOL Load (const char* filename, const char*root_name= "XmlRoot");

Do not save changes

void Discardchanges ();

Empty content

void Clear ();

A simple example of writing and saving:

Cxmlfile XmlFile;

Xmlfile.load ("File.xml");

Xmlfile.setlong ("student/Situation", "age", 24);

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", 25;

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.

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.