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 ;}