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 + +