title: What is the behavior of getAttributeNS?
body: <p>I'm writing a little program in JavaScript in which I want to parse the following little XML snippet:</p>
  
  <pre><code>&lt;iq xmlns="jabber:client" other="attributes"&gt;
    &lt;query xmlns="jabber:iq:roster"&gt;
      &lt;item subscription="both" jid="romeo@example.com"&gt;&lt;/item&gt;
    &lt;/query&gt;
  &lt;/iq&gt;
  </code></pre>
  
  <p>Because I don't know, if the elements and attributes have namespace prefixes, I'm using the namespace-aware functions (<code>getElementsByTagNameNS</code>, <code>getAttributeNS</code>).</p>
  
  <pre><code>var queryElement = iq.getElementsByTagNameNS('jabber:iq:roster', 'query')[0];
  if (queryElement) {
    var itemElements = queryElement.getElementsByTagNameNS('jabber:iq:roster', 'item');
    for (var i = itemElements.length - 1; i &gt;= 0; i--) {
      var itemElement = itemElements[i];
  
      var jid = itemElement.getAttributeNS('jabber:iq:roster', 'jid');
    };
  };
  </code></pre>
  
  <p>With this code I don't get the value of the attribute <code>jid</code> (I get an empty string), but when I use <code>itemElement.getAttribute('jid')</code> instead of <code>itemElement.getAttributeNS('jabber:iq:roster', 'jid')</code> I'm getting the expected result.</p>
  
  <p>How can I write the code in a namespace-aware manner? In my understanding of XML, the namespace of the attribute <code>jid</code> has the namespace <code>jabber:iq:roster</code> and therefore the function <code>getAttributeNS</code> should return the value <code>romeo@example.com</code>.</p>
  
  <p>[UPDATE] The problem was (or is) my understanding of the use of namespaces together with XML attributes and is not related to the DOM API. Therefor I created an other question: <a href="https://stackoverflow.com/questions/10672635/xml-namespaces-and-unprefixed-attributes">XML Namespaces and Unprefixed Attributes</a>. Also because <a href="https://stackoverflow.com/questions/41561/xml-namespaces-and-attributes">XML namespaces and attributes</a> unfortunately doesn't give me an answer.</p>
  
  <p>[UPDATE] What I did now, is to first check if there is the attribute without a namespace and then if it is there with a namespace:</p>
  
  <pre><code>var queryElement = iq.getElementsByTagNameNS('jabber:iq:roster', 'query')[0];
  if (queryElement) {
    var itemElements = queryElement.getElementsByTagNameNS('jabber:iq:roster', 'item');
    for (var i = itemElements.length - 1; i &gt;= 0; i--) {
      var itemElement = itemElements[i];
  
      var jid = itemElement.getAttribute('jid') || itemElement.getAttributeNS('jabber:iq:roster', 'jid');
  
    };
  };
  </code></pre>