tinyxml2 load xml errorID 10 -


i'm working on project in c++ using tinyxml2. have issue xml parsing , errorid 10 , error message "xml_error_parsing_text" when file loaded.

this following xml in question:

<game>   <window>     <width>600</width>     <height>500</height>     <background>jolibackgrounddegael.jpg</background>   </window>   <square>     <mario>       <size>         <width>30</width>         <height>15</height>       </size>       <speedperframe>5</speedperframe>       <font>         <stop>stopmario.jpg</stop>         <run>runmario.jpg</run>         <jump>jumpmario.jpg</jump>       </font>     </mario>   </square> </game> 

the xml file valid in w3c validator. think problem not here, maybe here :

void parsexml::getdoc() {     this->doc.loadfile(this->path);     if (this->doc.errorid() != 0)     {         printf("load file=[%s] failed\n", this->doc.geterrorstr1());         printf("load file=[%s] failed\n", this->doc.geterrorstr2());     } } 

when in loadfile function breakpoint, see load file same below.

here complete code :

#include "caracteristique.h" #include <iostream>  #include <direct.h> #define getcurrentdir _getcwd  using namespace tinyxml2;  const char* parsexml::path = "xmltype.xml";  void parsexml::getdoc() {     this->doc.loadfile(this->path);     if (this->doc.errorid() != 0)     {         printf("load file=[%s] failed\n", this->doc.geterrorstr1());         printf("load file=[%s] failed\n", this->doc.geterrorstr2());     } }  int parsexml::getwindowheight() {     if (this->doc.error())         this->getdoc();      xmlelement *root = this->doc.rootelement();     if (!root)     {         xmlelement *window = root->firstchildelement("window");         if (!window)             std::cout <<  window->firstchildelement("height")->firstchild()->totext() << std::endl;     }     return 0; } 

an idea ?

thanks help,

don't forget loadfile method load , parse file. if file doesn't follow xml standards, method fail , return false. should verify none of xml attributes contains special caracters (,),/,\ exemple. there's small example on page: tiny xml parser example

here's exemple tiny modifications:

#include "tinyxml.h"   #include <iostream> #include <string> using namespace std;   void parcours( tixmlnode* node, int level = 0 ) {     cout << string( level*3, ' ' ) << "[" << node->value() << "]";     if ( node->toelement() )     {         tixmlelement* elem = node->toelement();         ( const tixmlattribute* attr = elem->firstattribute(); attr; attr = attr->next() )             cout << " (" << attr->name() << "=" << attr->value() << ")";     }     cout << "\n";           for( tixmlnode* elem = node->firstchild(); elem; elem = elem->nextsibling() )         parcours( elem, level + 1 ); }   int main( int argc, char* argv[] ) {     tixmldocument doc("c:/test.xml" );     bool loadokay = doc.loadfile();     if ( !loadokay ) {         cerr << "could not load test file. error='" << doc.errordesc() << "'. exiting.\n";         return 1;     }      parcours( doc.rootelement() ); } 

you try xml document this:

<parent>     <child1 test="program" />         <child2>         <node number="123456789" />           </child2>     <child3>                 <hello world="!!!" />     </child3>     </parent> 

i tried , worked well, have execute code passing name of file in first argument.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -