c++ - Parsing XML files: Root Nodes has no child nodes -


i never worked xml , xml parsers , wanted parse collada document model animation opengl.

i using tinyxml2 parser , seems doing wrong that.

xmldocument _doc; _doc.loadfile(path.c_str());  xmlnode* proot = _doc.firstchild();  xmlnode* pelement =  proot->firstchildelement("library_geometries"); 

i working xcode , in debugging mode can see, pelement null proot has got no child nodes.

in tinyxml2 node, not elements. _doc.firstchild() unhelpful it's taking node before <collada> element (probably attribute in xml header). want first child element in document, i.e. <collada> followed first <library_geometries> element below it. try this:

#include "tinyxml2.h" using namespace tinyxml2; int main() {    xmldocument doc;    doc.loadfile ("collada.xml");     auto colladaelement = doc .firstchildelement();    auto lib_geomelement = colladaelement -> firstchildelement("library_geometries");     return 0; } 

and, if want more of c++11/14 experience try tinyxml2 extension reduces above to:

#include "tixml2ex.h" int main() {    tinyxml2::xmldocument doc;    doc.loadfile ("collada.xml");    auto lib_geomelement = find_element (doc, "collada/library_geometries");     return 0; } 

Comments

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

android - ConstraintLayout: Realign baseline constraint in case if dependent view visibility was set to GONE -

c# - Populating Gridview inside Listview ItemTemplate On Web User Control from Code Behind -