C ++ parses XML (using tinyxml)

Source: Internet
Author: User

The environment is vs2010 + Windows 7.

I downloaded the timyxml library here and compiled it directly to get tinyxml. Lib.

Tinyxml. H files are also required for use.

If you do not want to compile the SDK, you can download the compiled lib here. By the way, an H file is provided.

The XML file parsed in my program can be found here.

The Code is as follows:

# Include <iostream> # include <string> # include "tinyxml. H "using namespace STD; # pragma comment (Lib," tinyxml. lib ") int main () {const char * xmlfile =" lianxi. XML "; tixmldocument Doc; Doc. loadFile (xmlfile); // Doc. print (); // output XML file to see tixmlelement * firstlevel = Doc. rootelement (); cout <firstlevel-> value () <":" <Endl;/* in some cases, such: <menu name = "123" num = "456"> </menu> tixmlattribute * firstatt = firstleve L-> firstattribute (); While (firstatt! = NULL) {cout <firstatt-> name () <":" <firstatt-> value (); firstatt = firstatt-> next ();} */tixmlelement * secondlevel = firstlevel-> firstchildelement (); While (secondlevel! = NULL) {cout <"; cout <secondlevel-> value () <": "<Endl; tixmlelement * thirdlevel = secondlevel-> firstchildelement (); while (thirdlevel! = NULL) {cout <"; cout <thirdlevel-> value () <": "<thirdlevel-> gettext () <Endl; thirdlevel = thirdlevel-> nextsiblingelement ();} secondlevel = secondlevel-> nextsiblingelement ();} cin. get (); Return 0 ;}

 

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.