Tinyxml op by C ++

Source: Internet
Author: User

Tinyxml is a simple, small, C ++ XML parser that can be easily integrated into other programs.

Tinyxml sourcecode: http://sourceforge.net/projects/tinyxml/

Tinyxml only needs to create the DOM tree through first child and next sibling. Then, the whole tree is traversed by using the pointer of the root node as the starting point.

Below is a section of self-operated XMLCode. (C ++)

Typedef struct queueinfo * pqueueinfo; struct queueinfo {int struct; char m_chqueueip [20]; int m_iqueueport; vector <int> m_vctdatatype ;}; typedef struct serverinfo * pserverinfo; struct serverinfo {string m_mongoip; int m_mongoport; string m_mongodbname; double m_mongotimeout; string m_logprefix; string m_logdir; string delimiter; int m_queserverport; int m_queserverid; int m_queservercount; int Interval; vector <queueinfo> m_vctqueueinfo;}; Class serverconf {public: bool readxmlcfg (const char * _ path, pserverinfo _ psi );};

Bool serverconf: readxmlcfg (const char * _ path, pserverinfo _ psi) {tixmldocument * mydocument = new tixmldocument (_ path); If (null = mydocument) {ac_error ("can't init % s", _ path); Return false;} mydocument-> LoadFile (); tixmlelement * proot = mydocument-> rootelement (); if (null = proot) {ac_error ("can't init XML root"); Return false;} // read mongoserver tixmlelement * pmongo = proot-> firstchildeleme NT ("mongodbservercfg"); If (null = pmongo) {ac_error ("can't find queueservicecfg"); Return false ;} _ psi-> m_mongoip = pmongo-> attribute ("serverip"); _ psi-> m_mongoport = atol (pmongo-> attribute ("SERVERPORT ")); _ psi-> m_mongodbname = pmongo-> attribute ("dbname"); _ psi-> m_mongotimeout = atol (pmongo-> attribute ("timeout ")); // read queueserver tixmlelement * pqueues = pmongo-> nextsiblingelement ("queueservercf G "); If (null = pqueues) {ac_error (" can't find queueservicecfg "); Return false ;} _ psi-> m_queserverip = pqueues-> attribute ("serverip"); _ psi-> m_queserverport = atol (pqueues-> attribute ("SERVERPORT ")); _ psi-> m_queserverid = atol (pqueues-> attribute ("ID"); _ psi-> m_queservercount = atol (pqueues-> attribute ("count ")); _ psi-> m_queserverdid = atol (pqueues-> attribute ("did");/* cyclically retrieve queue configuration */tixmlelement * PQ Ueuechild = pqueues-> firstchildelement ("queuecfg"); While (null! = Pqueuechild) {struct queueinfo qiobj; qiobj. m_iqueueid = atoi (pqueuechild-> attribute ("ID");/* ID */memcpy (qiobj. m_chqueueip, pqueuechild-> attribute ("ip"), strlen (pqueuechild-> attribute ("ip");/* IP */qiobj. m_iqueueport = atoi (pqueuechild-> attribute ("Port");/* port */char * strbuf = NULL; char * strtoken; const char * STR = pqueuechild-> attribute ("datatype");/* datatype */string strdatatype (STR ); Strtoken = strtok_r (& strdatatype [0], ",", & strbuf); While (strtoken! = NULL) {qiobj. m_vctdatatype.push_back (atoi (strtoken); strtoken = strtok_r (null, ",", & strbuf);} _ psi-> m_vctqueueinfo.push_back (qiobj ); pqueuechild = pqueuechild-> nextsiblingelement ("queuecfg");} Delete mydocument; return true ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.