Note that there are some explanatory texts on larger screens.

plurals
  1. POQtXML DOM parsing / iTunes Library
    primarykey
    data
    text
    <p>I'm trying to get a list of the iTunes albums, by parsing the XML library (iTunes Music Library.xml in the iTunes directory).</p> <pre><code>#include &lt;iostream&gt; #include &lt;QtCore&gt; #include &lt;QFile&gt; #include &lt;QtXml&gt; using namespace std; void parse(QDomNode n) { while(!n.isNull()) { // If the node has children if(n.hasChildNodes() &amp;&amp; !n.isNull()) { // We get the children QDomNodeList nChildren = n.childNodes(); // We print the current tag name //std::cout &lt;&lt; "[~] Current tag : &lt;" &lt;&lt; qPrintable(n.toElement().tagName()) &lt;&lt; "&gt;" &lt;&lt; std::endl; // And for each sub-tag of the current tag for(int i = 0; i &lt; nChildren.count(); i++) { // We get the children node QDomNode nChild = nChildren.at(i); // And the tag value (we're looking for *Album* here) QString tagValue = nChild.toElement().text(); // If the tag isn't null and contain *Album* if(!nChild.isNull() &amp;&amp; tagValue == "Album") { // The album name is in the next tag QDomElement albumNode = nChild.nextSiblingElement(); std::cout &lt;&lt; "[-] Album found -&gt; " &lt;&lt; qPrintable(albumNode.text()) &lt;&lt; std::endl; } // And we parse the children node parse(nChild); } } n = n.nextSibling(); } } int main() { QDomDocument doc("Lib"); QFile file("/Users/wizardman/QtRFIDMusic/Lib.min.xml"); if(!file.open(QIODevice::ReadOnly)) return 1; if(!doc.setContent(&amp;file)) { file.close(); return 1; } file.close(); // Root element QDomElement docElem = doc.documentElement(); // &lt;plist&gt; -&gt; &lt;dict&gt; QDomNode n = docElem.firstChild().firstChild(); cout &lt;&lt; endl &lt;&lt; "Album list" &lt;&lt; endl; cout &lt;&lt; "------------------------------------" &lt;&lt; endl; parse(n); return 0; } </code></pre> <p>The iTunes' XML is not really standart XML, the name of the album is stored in the node next to the <code>&lt;key&gt;Album&lt;/key&gt;</code> for each entry. <a href="http://pastebin.com/CpELtcC4" rel="nofollow">Here is what it looks like</a>. I intentionnaly renamed some nodes for debugging purpose (to see if I reach them in my output).</p> <p>And here is my output :</p> <pre><code>Album list ------------------------------------ [-] Album found -&gt; J Dilla - Legacy Vol.1 [-] Album found -&gt; J Dilla - Legacy Vol.2 [-] Album found -&gt; J Dilla - Legacy Vol.1 [-] Album found -&gt; J Dilla - Legacy Vol.2 [-] Album found -&gt; J Dilla - Legacy Vol.2 [-] Album found -&gt; J Dilla - Legacy Vol.2 </code></pre> <p>I can't see why the loop is reparsing the first nodes. Any ideas ?</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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