Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting QDomElement to QString / Container class
    primarykey
    data
    text
    <p>Let's say we have the following XML document:</p> <pre><code>&lt;root&gt; &lt;options&gt; ... &lt;/options&gt; &lt;children&gt; &lt;child name="first"&gt;12345&lt;/child&gt; &lt;child name="second"&gt; &lt;additionalInfo&gt;abcd&lt;/additionalInfo&gt; &lt;/children&gt; &lt;/root&gt; </code></pre> <p>I would like to get a string representation of the "child" nodes and append them into an array (I don't want to lose the XML syntax so .text() is not an option). For example, the first child would look like: </p> <pre><code>QString child = "&lt;child name="first"&gt;12345&lt;/child&gt;"; </code></pre> <p>I used the following code to get the elements:</p> <pre><code>QDomDocument doc; QDomElement element; element = xml-&gt;documentElement(); if(element.isNull() == false) { element = element.firstChildElement("children"); if(element.isNull()) return; element = element.firstChildElement("child"); while(element.isNull() == false) { doc = element.toDocument(); if(doc.isNull() == false) { // save string into array array.append(doc.toString()); } element = element.nextSiblingElement("child"); } } </code></pre> <p>The problem is that the doc.isNull returns always false (looks like I'm unable to convert the element into document). Is there any way how I can perform this?</p> <p><strong>Edit:</strong></p> <p>I would like to add that QString is not mandatory here. Basically any class that can be later used to retrieve the data is ok (I'll save these nodes and use them to initialize another objects later on). Important thing is that I should be able to access those values even when the original document have been destroyed.For example, it it possible to store those elements directly to some array (e.g. QList), which can be used to access them later on. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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