How to Use tinyxml to parse XML documents:
Tinyxml parser is an open-source XML file parser.
This example is used to parse an XML file.
The content of the XML file is
<? XML version = "1.0" encoding = "gb2312"?>
<Root>
<Record>
<Name ID = "visual"> </Name>
</Record>
<Record>
<Name ID = "design"> or a Biao </Name>
</Record>
</Root>
# Include <iostream>
# Include <tinyxml. h>
Using namespace STD;
Int main (INT, char * [])
{
Tixmldocument dom ("D:/1.xml ");
Bool bsuccess = Dom. LoadFile ();
If (! Bsuccess)
{
Cout <"failed to open! "<Endl;
Cout <"error cause:" <Dom. errordesc () <Endl;
}
Tixmlelement * pelement = Dom. firstchildelement ();
Tixmlnode * precord = pelement-> firstchild ("record ");
While (precord! = 0)
{
// Get the content in the node
Tixmlnode * pname = precord-> firstchild ("name ");
Tixmlelement * pnameele = pname-> toelement ();
Cout <"End name:" <pnameele-> value () <Endl;
Cout <"content:" <pnameele-> gettext () <Endl;
// Obtain the node attributes
Cout <"node attributes" <pnameele-> attribute ("ID") <Endl;
// Find a brother on the same layer as yourself
Precord = precord-> nextsibling ("record ");
}
Getchar ();
Return 0;
}