Example of tinyxml usage and tinyxml usage
Currently, many protocols are designed with xml to facilitate expansion and compatibility. The popular json and gson are not mentioned, and tinyxml with many applications is also very good. The following describes how to use and use tinyxml.
To use tinyxml, you must include the source code in the project and establish a reference relationship in the header file. The following is a simple example to print the xml file according to the hierarchy.
The Code is as follows:
# Include "stdafx. h "# include" targetver. h "# include" tinystr. h "# include" SystemCommon. h "# include" tinyxml. h "void ParseXML (TiXmlElement * Element); int _ tmain (int argc, _ TCHAR * argv []) {char c [2048] =" <! -- This is a comment --> "" <? Xml version = \ "1.0 \" encoding = \ "UTF-8 \"?> "" <Class name = \ "computer software Class \"> Computer "" <Students> "" <student name = \ "Zhang San \" studentNo = \ "13031001 \" sex = \ "male \" age = \ "22 \"> "" <phone> 88208888 </phone> "" <ET name = \ "de \" ground = \ "ground \ "> on the ground </ET>" "<et name = \" et name \ "ball = \" ball \ "/>" "<address> No. 2 Taibai South Road, Xi'an </address> "" </student> "" <student name = \ "Li Si \" studentNo = \ "13031002 \" sex = \ "male \" age = \ "20 \ ">" "<phone> 88206666 </phone>" "<address> Guanghua Road, Xi'an </address> "" </Student> "" </Students> "" </Class> "; TiXmlDocument * myDocument = new TiXmlDocument (); // assume that the file name is xml. xml myDocument-> LoadFile ("xml. xml ", TIXML_ENCODING_UTF8); // myDocument-> Parse (c, 0, TIXML_ENCODING_UNKNOWN); TiXmlElement * rootElement = myDocument-> RootElement (); while (rootElement) {ParseXML (rootElement); rootElement = rootElement-> NextSiblingElement ();} delete myDocument; cout <"-------------- -- END ----------------- "<endl; return 0;} void PrintTree (int c) {if (c <= 0) return; while (c) {cout <""; -- c;} return;} // call tinyxml to parse xml void ParseXML (TiXmlElement * pElement) {static int I = 0; PrintTree (I ); cout <pElement-> Value () <""; const char * str = NULL; if (str = pElement-> GetText ()) cout <"" <str <endl; else cout <endl; TiXmlAttribute * attributeOfStudent = pElement-> FirstAttribu Te (); while (attributeOfStudent) {PrintTree (I); std: cout <attributeOfStudent-> Name () <":" <attributeOfStudent-> Value () <std: endl; attributeOfStudent = attributeOfStudent-> Next ();} TiXmlElement * ChildElement = pElement-> FirstChildElement (); while (NULL! = ChildElement) {I ++; ParseXML (ChildElement); I --; ChildElement = ChildElement-> NextSiblingElement ();}}
For example, the file content to be parsed is
<?xml version="1.0" encoding="utf-8"?><!-- This is a comment --><Class name="Class of SoftWare"> <Students> <student name="LiLei" studentNo="13031001" sex="Man" age="22"> <phone>88208888</phone> <ET name="de" ground = "ground">on the ground <et name = "et name" ball = "ball"/> </ET> <address>Road1</address> </student> <student name="LiSi" studentNo="13031002" sex="Man" age="20"> <phone>88206666</phone> <address>Road2</address> </student> </Students> <Teatcher>few teatchers </Teatcher></Class>
Reprinted please indicate original link: http://blog.csdn.net/wujunokay/article/details/38310691
How to Use Tinyxml in vs2010
Is there an actual example?
Which contains the header files
There is an example in the source file you downloaded.
Problem about using TinyXml in vs2012 mfc
Precompiled header file. Remove the precompiled header option from the project properties.