Two methods to search for elements in tinyxml correspond to two different XML file formats. </P> <p> test2.xml file: </P> <p> View plaincopy to clipboardprint? <Br/> renew <br/> <? XML version = "1.0" encoding = "UTF-8"?> <Br/> <document> <br/> <English name = "my" value = "UTF32"> the world has programming languages </English> <br/> <button name = "OK _btn" x = "20" Y = "77"> OK </button> <br/> </document> <br/> quit --------------------------------------------------------------------------------------------------- --------------------- <Br/> <? XML version = "1.0" encoding = "UTF-8"?> <Br/> <document> <br/> <English name = "my" value = "UTF32"> the world has programming languages </English> <br/> <button name = "OK _btn" x = "20" Y = "77"> OK </button> <br/> </document> <br/> quit </P> <p> CPP Code: </P> <p> View plaincopy to clipboardprint? <Br/> # include ".. /tinyxml. H "<br/> # include <iostream> <br/> # include <string> <br/> int main (void) <br/>{< br/> tixmldocument DOC ("test2.xml"); <br/> Doc. loadFile (); <br/> tixmlhandle doch (& Doc); <br/> tixmlelement * element = doch. firstchildelement ("document "). firstchildelement ("button "). element (); <br/> STD: cout <"<" <element-> value () <">" <STD: Endl; <br/> STD: cout <"name =" <element-> Attribute ("name") <STD: Endl; <br/> STD: cout <"x =" <element-> attribute ("X ") <STD: Endl; <br/> STD: cout <"Y =" <element-> attribute ("Y") <STD: Endl; <br/> STD: cout <"text =" <element-> gettext () <STD: Endl; <br/> getchar (); <br/> return 0; <br/>}< br/> # include ".. /tinyxml. H "<br/> # include <iostream> <br/> # include <string> <br/> int main (void) <br/>{< br/> tixmldocument DOC ("Test2. XML "); <br/> Doc. loadFile (); <br/> tixmlhandle doch (& Doc); <br/> tixmlelement * element = doch. firstchildelement ("document "). firstchildelement ("button "). element (); <br/> STD: cout <"<" <element-> value () <">" <STD: Endl; <br/> STD: cout <"name =" <element-> attribute ("name") <STD: Endl; <br/> STD :: cout <"x =" <element-> attribute ("X") <STD: Endl; <br/> STD :: cout <"Y =" <element-> attribute ("Y") <STD: Endl; <br/> STD: cout <"text =" <element-> gettext () <STD: Endl; <br/> getchar (); <br/> return 0; <br/>}</P> <p> the element pointer here is the pointer of the current operation, through doch. firstchildelement ("document "). firstchildelement ("button "). element (); method we get the pointer to the button element to be searched for, and then its elements can be passed through element-> attribute ("name "); element-> attribute ("X") comes, which is very convenient to use. </P> <p> test. xml file: </P> <p> View plaincopy to clipboardprint? <Br/> renew <br/> <? XML version = "1.0" encoding = "UTF-8"?> <Br/> <persons> <br/> <student> <br/> <stu_name> Hami </stu_name> <br/> <stu_age> 15 </stu_age> <br /> <stu_sex> male </stu_sex> <br/> </student> <br/> <teacher> <br/> <tea_name> Alin </tea_name> <br/> <tea_age> 16 </tea_age> <br/> <tea_sex> female </tea_sex> <br/> </teacher> <br/> </persons> <br/> snapshots <br/>- Snapshot <br/> <? XML version = "1.0" encoding = "UTF-8"?> <Br/> <persons> <br/> <student> <br/> <stu_name> Hami </stu_name> <br/> <stu_age> 15 </stu_age> <br /> <stu_sex> male </stu_sex> <br/> </student> <br/> <teacher> <br/> <tea_name> Alin </tea_name> <br/> <tea_age> 16 </tea_age> <br/> <tea_sex> female </tea_sex> <br/> </teacher> <br/> </persons> <br/> latency </P> <p> CPP Code: </P> <p> View plaincopy to clipboardprint? <Br/> # pragma comment (Lib, "tinyxml. lib ") <br/> # include" tinyxml. H "<br/> # include <iostream> <br/> # include <string> <br/> # define tixml_use_stl <br/> int main (void) <br/>{< br/> tixmldocument * persondoc = new tixmldocument; <br/> persondoc-> LoadFile ("test. XML "); <br/> tixmlelement * personelement = persondoc-> rootelement (); <br/> STD: cout <personelement-> value () <STD :: endl; <br/> tixmlelement * student = PE Rsonelement-> firstchildelement (); <br/> STD: cout <"" <student-> value () <STD: Endl; <br/> tixmlelement * nameelement = student-> firstchildelement (); <br/> STD: cout <"<nameelement-> value (); // <STD: Endl; <br/> // STD: cout <"" <nameelement-> gettext () <STD: Endl; <br/> tixmlelement * ageelement = nameelement-> nextsiblingelement (); <br/> STD: cout <"<ageelement-> value () <STD :: endl; <br/> tixmlelement * Sexelement = ageelement-> nextsiblingelement (); <br/> STD: cout <"" <sexelement-> value () <STD: Endl; <br/> tixmlelement * teacher = student-> nextsiblingelement (); <br/> STD: cout <"<teacher-> value () <STD :: endl; <br/> tixmlelement * teanameelement = teacher-> firstchildelement (); <br/> STD: cout <"" <teanameelement-> value () <STD: Endl; <br/> tixmlelement * teaageelement = teanameelement-> nextsiblingelem ENT (); <br/> STD: cout <"" <teaageelement-> value () <STD: Endl; <br/> tixmlelement * teasexelement = teaageelement-> nextsiblingelement (); <br/> STD: cout <"" <teasexelement-> value () <STD :: endl; <br/> return 0; <br/>}< br/> # pragma comment (Lib, "tinyxml. lib ") <br/> # include" tinyxml. H "<br/> # include <iostream> <br/> # include <string> <br/> # define tixml_use_stl <br/> int main (void) <br/>{< br/> tixmldocument * Persondoc = new tixmldocument; <br/> persondoc-> LoadFile ("test. XML "); <br/> tixmlelement * personelement = persondoc-> rootelement (); <br/> STD: cout <personelement-> value () <STD :: endl; <br/> tixmlelement * student = personelement-> firstchildelement (); <br/> STD: cout <"<student-> value () <STD: Endl; <br/> tixmlelement * nameelement = student-> firstchildelement (); <br/> STD :: cout <"" <nameelement-> value (); // <STD: Endl; <br/> // STD: cout <"<nameelement-> gettext () <STD: Endl; <br/> tixmlelement * ageelement = nameelement-> nextsiblingelement (); <br/> STD: cout <"<ageelement-> value () <STD :: endl; <br/> tixmlelement * sexelement = ageelement-> nextsiblingelement (); <br/> STD: cout <"<sexelement-> value () <STD: Endl; <br/> tixmlelement * teacher = student-> nextsiblingelement (); <br/> STD: cout <"<teach Er-> value () <STD: Endl; <br/> tixmlelement * teanameelement = teacher-> firstchildelement (); <br/> STD :: cout <"" <teanameelement-> value () <STD: Endl; <br/> tixmlelement * teaageelement = teanameelement-> nextsiblingelement (); <br/> STD: cout <"" <teaageelement-> value () <STD: Endl; <br/> tixmlelement * teasexelement = teaageelement-> nextsiblingelement (); <br/> STD: cout <"" <teasexelement-> value () <STD :: en DL; <br/> return 0; <br/>}</P> <p> the nextsiblingelement () function is used here and points to the next sibling node, this operation can get the pointer of the next sibling node without having to know any other information about the sibling node. But the first method, for example, in tixmlelement * element = doch. firstchildelement ("document "). firstchildelement ("button "). element ();, you must know the "document", "button" and other information. </P> <p> edit a subnode <br/> you can insert or delete a subnode that replaces all the subnodes. </P> <p> tixmlnode * insertendchild (const tixmlnode & addthis); </P> <p> tixmlnode * insertbeforechild (tixmlnode * beforethis, const tixmlnode & addthis ); </P> <p> tixmlnode * insertafterchild (tixmlnode * afterthis, const tixmlnode & addthis); </P> <p> the preceding three functions are used to insert nodes, the insertendchild function allows you to insert new nodes to the end. The insertbeforechild and insertafterchild functions allow you to insert nodes before and after the specified node location. </P> <p> tixmlnode * replaceChild (tixmlnode * replacethis, const tixmlnode & withthis); </P> <p> the replaceChild function is used to replace the specified node. </P> <p> bool removechild (tixmlnode * removethis); </P> <p> void clear (); </P> <p> the removechild function allows you to delete a specified node. </P> <p> the clear function deletes all child nodes of the current node (including child nodes included in the child node), but does not modify the current node. </P> <p> this article from the csdn blog, reprinted please indicate the source: http://blog.csdn.net/nieyong2010/archive/2010/01/22/5224243.aspx #