getElementsByTagNameNS does not seem to work #449

Open
rpbouman opened this Issue May 19, 2012 · 0 comments

Projects

None yet

2 participants

@rpbouman

getElementsByTagNameNS does not seem to work. Example code:

var xml = <edi:x xmlns:edi="http://ecommerce.example.org/schema"></edi:x>';
response.write("xml: " + xml);

var jsdom = require("jsdom");
var doc = jsdom.jsdom(xml, jsdom.level(1, "core"), null);

var els, i, n, el;

els = doc.getElementsByTagNameNS("http://ecommerce.example.org/schema", "x");
n = els.length;
for (i = 0; i < n; i++) {
    el = els.item(i);
    response.write("\nnodename: " + el.nodeName + ", namespaceURI: " + el.namespaceURI);
}

The code above yields an empty list in els; in other words,

doc.getElementsByTagNameNS("http://ecommerce.example.org/schema", "x") 

fails to select any elements whereas it should select the only element in the document.

It can be shown that the doc is parsed ok, as this snippet:

response.write("\n\ngetElementsByTagName: *");
els = doc.getElementsByTagName("*");
n = els.length;
for (i = 0; i < n; i++) {
    el = els.item(i);
    response.write("\nnodename: " + el.nodeName + ", namespaceURI: " + el.namespaceURI);
}

does yield the element.

For my particular use case, I could work around a properly working getElementsByTagNameNS, so I tried explicitly to create a dom level 1 core parser like so:

var jsdom = require("jsdom");
var doc = jsdom.jsdom(xml, jsdom.level(1, "core"), null);

However, this still features a getElementsByTagNameNS method:

response.write("\n\ndoc.getElementsByTagNameNS: " + typeof(doc.getElementsByTagNameNS));

(I assumed a dom level 1 core document would not have this method so I could fallback to the regular getElementsByTagName, but alas)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment