Cxmlparse guide for XML parsing in VC

Source: Internet
Author: User

Description

The original version of the cxmlparse class is from codeproject.com.

Http://download.csdn.net/source/534628

During years of use, I made some upgrades,

Including:

1. modified some original author bugs.

2. Added support for Chinese Parsing

3. Remove the dependency on MFC and change it to stl c ++.

Common interface functions

1. bool load (const char * szfilename); load XML document content from XML file

2. bool save (const char * szfilename); Archive

3. addelem add nodes

4. addchildelem Add a subnode

5. Add node attributes to addattrib

6. addchildattrib adds subnode attributes

7. intoelem enters the subnode

8. outofelem jumps out of the subnode

Example

1. document loading and saving

Cxmlparse XML;

XML. Load ("C: // demo. xml ");

XML. Save ("C: // export. xml ");

2. Create an XML document

Cxmlparse XML;

XML. addelem ("Demo ");

XML. addchildelem ("child ");

XML. addchildattrib ("name", "nieo ");

XML. addchildattrib ("sex", 1 );

The XML content is

<Demo> <child name = "nieo" Sex = "1"/> </demo>

3. Create multi-layer XML documents

Cxmlparse XML;

XML. addelem ("Demo ");

XML. addchildelem ("root ");

XML. cancelem ();

XML. addchildelem ("child ");

XML. addchildattrib ("name", "nieo ");

XML. addchildelem ("child ");

XML. addchildattrib ("name", "Simen ")

XML. outofelem ();

The XML content is

<Demo> <root> <child name = "nieo"/> <child name = "Simen"/> </root> </demo>

4. XML document parsing take the following document as an Example

<HTML>

<Header> <meta name = "author" content = "csdn"/>

<Body> <nieo sex = "1" nickname = "nieoding"/> </body>

Find nieo's nickname.

Cxmlparse XML;

XML. Load (.....);

XML. findchildelem ("body ");

XML. cancelem ();

If (XML. findchildelem ("nieo "))

{

String nickname = xml. getchildattrib ("nickname ")

}

5. Interaction between STD: string and cxmlparse

Cxmlparse-> STD: String

Cxmlparse XML;

.........

STD: String Doc = xml. getdoc ();

STD: String-> cxmlparse

STD: String Doc = "<body>... </body> ";

Cxmlparse XML (Doc. c_str ());

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.