Working with XML files in C + +

Source: Internet
Author: User

The environment is Vs2010+windows 7.

Timyxml Library I was here to download, directly can compile, compiled to get tinyxml.lib.

Tinyxml.h files are also required for use.

If you do not want to compile, here can download my compiled lib, incidentally with the H file.

The XML files 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;

/*
Some of these things will be annotated with these
Like what:
<menu name= "123" num= "456" >
</menu>

Tixmlattribute *firstatt=firstlevel->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;
}

Working with XML files in C + +

Related Article

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.