title: Reading multiple Xml Attributes with qml
body: <p>I've got and XML String in javascript (qml). My goal is to filter informations regarding different lines. I want an object containing the line name ( attribute) and especially the countdowns. For one line name there are departures_count * countdown fields. I want all these (in the current case its 2) countdown values in an array. And the ultimate goal is to load the whole line in a ListModel of the form: <code>line(name, countdown(1,2,..x))</code>.</p>
  
  <p>The big problem is to access the attributes. In qml somehow the standard functions for the DOM tree are not supported: "Object has no such function as getAttribute()" and others aswell, like getElementByTagName(). With XmlListModel I can access attributes, but just if there is just one. In each other case it returns unknown (there is a bug in qt as far as I found out).</p>
  
  <p>I allready tried pure XmlListModel, but had no luck (see: <a href="https://stackoverflow.com/questions/19244672/parse-xmlhttprequest-to-xmllistmodel">Parse XmlHttpRequest to XmlListModel</a>) - there multiple entries are not supported. So I try to find a workarround:</p>
  
  <p>To be processed XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; 
  &lt;ft&gt; 
    &lt;response&gt; 
      &lt;client device="" appName="" clientId="123" appVersion=""/&gt; 
      &lt;responseType&gt;api_get_monitor&lt;/responseType&gt; 
      &lt;responseTime&gt;2011-05-31 14:41:13&lt;/responseTime&gt; 
      &lt;monitor id="36469" clientexpiration=""&gt; 
        &lt;lines count="24"&gt; 
          &lt;line name="U1" type="ptMetro" towards="Leopoldau" direction="H" platform="U1_H" barrierFree="1" realtimeSupported="1"&gt; 
            &lt;departures count="2"&gt; 
              &lt;departure&gt; 
                &lt;departureTime delay="" countdown="3"/&gt; 
              &lt;/departure&gt; 
              &lt;departure&gt; 
                &lt;departureTime  delay="" countdown="6"/&gt; 
              &lt;/departure&gt; 
              &lt;firstDeparture&gt; 
                &lt;departureTime  delay="" countdown=""/&gt; 
              &lt;/firstDeparture&gt; 
              &lt;lastDeparture&gt; 
                &lt;departureTime  delay="" countdown=""/&gt; 
              &lt;/lastDeparture&gt; 
            &lt;/departures&gt; 
          &lt;/line&gt;
        &lt;/lines&gt; 
      &lt;/monitor&gt; 
      &lt;trafficInfos/&gt; 
      &lt;message messageCode="1"&gt;ok&lt;/message&gt; 
    &lt;/response&gt; 
  &lt;/ft&gt; 
  </code></pre>
  
  <h1>1 climbing the Object xml tree</h1>
  
  <p>With </p>
  
  <pre><code> function getElementsByTagName(rootElement, tagName) {
          var childNodes = rootElement.childNodes;
          var elements = [];
          for(var i = 0; i &lt; childNodes.length; i++) {
              if(childNodes[i].tagName === tagName) {
                  elements.push(childNodes[i]);
              }
          }
          return elements;
      }
  </code></pre>
  
  <p>I can dig in to get the element line out of the whole xml tree.</p>
  
  <pre><code>attributeInterface.xml = depatures[0];
  attributeInterface.query = "/"
  attributeInterface.roles.name = "countdown";
  attributeInterface.roles.query = "@countdown/string()";
  </code></pre>
  
  <p>and with this:</p>
  
  <pre><code>XmlListModel {
      id: attributeInterface
  
      onStatusChanged: {
          for (var i = 0; i &lt; count; i++) {
              console.debug({"countdown": parseFloat(get(i).countdown) });
          }}}
  </code></pre>
  
  <p>I tried to get the attributes out. But the problem there is, that the assignment is invalid, because the xml-elements are objects (DOM? but the methods for such are not there..) and not text.</p>
  
  <h1>2 Regex</h1>
  
  <p>So my last bet, is to use regular expressions. Is there a way to get ALL countdown values? This is my best try, but it somehow just gets one value (i tried the + at the end to find all countdowns, but it wouldnt work. <code>/delay\=\"\d*\".countdown\=\"(\d*)\"+/</code></p>
  
  <p>And this
  <code>for(var i = 0; i&lt;5; i++)    console.debug(found[i]);</code> is how I retrieve the matches. The second iteration, so found[1] gives me 1 correct countdown. But how do I expand this concept to get all the countdowns?</p>