Note that there are some explanatory texts on larger screens.

plurals
  1. POC++: Trouble with Parsing XML using Libxml
    text
    copied!<p>I am having a lot of trouble working with the libxml2 library to parse an xml file.</p> <p>I have weeded out a previous, similar problem, but have run into another.</p> <p>Here is the problem code:</p> <pre><code>class SSystem{ public: //Constructors SSystem(){}; //Make SSystem from XML Definition. Pass ptr to node SSystem(xmlNodePtr Nptr, xmlDocPtr Dptr){ name = wxString((char *)xmlGetProp(Nptr, (xmlChar*)"name"), wxConvUTF8); //Move to next level down, the &lt;general&gt; element Nptr = Nptr-&gt;xmlChildrenNode; //Move one more level down to the &lt;radius&gt; element Nptr = Nptr-&gt;xmlChildrenNode; //Get Radius value if (!xmlStrcmp(Nptr-&gt;name, (const xmlChar *)"radius")) { char* contents = (char*)xmlNodeGetContent(Nptr); std::string test1 = std::string(contents); radius = wxString(contents, wxConvUTF8); } } </code></pre> <p>Both an xmlNodePtr and an xmlDocPtr are passed to the constructor, which works fine taking just a property ("name"), but is now choking on further parsing.</p> <p>Here is a piece of the xml file in question:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;Systems&gt; &lt;ssys name="Acheron"&gt; &lt;general&gt; &lt;radius&gt;3500.000000&lt;/radius&gt; &lt;-- I am trying to get this value (3500). &lt;stars&gt;300&lt;/stars&gt; &lt;asteroids&gt;0&lt;/asteroids&gt; &lt;interference&gt;0.000000&lt;/interference&gt; &lt;nebula volatility="0.000000"&gt;0.000000&lt;/nebula&gt; &lt;/general&gt; </code></pre> <p>It compiles fine, but crashes when the constructor is loaded (I know because, if I comment out the if conditional and the char* contents = (char*)xmlNodeGetContent(Nptr->xmlChildrenNode), it runs fine.</p> <p>I've tried so many different things (removed one of the Nptr->xmlChildrenNode), but nothing works.</p> <p>What is wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload