nodelist

How is the NodeList implemented?

The DOM NodeList (as returned e.g. by element.getElementsByTagName) is an interesting object, in that it is not a snapshot, but reflects changes to the document made after you have created the NodeList. I was wondering how one would implement such a collection: Completely lazy evaluation must be horribly slow, but keeping a cached vers...

JavaScript NodeList

Hello All, is there a way to join 2 NodeLists returned by 2 calls of document.getElementsByTagName? Say, I have the following code var inputs = documentElement.getElementsByTagName('input'); var selects = document.getElementsByTagName('select'); I want to loop through the results. Is it possible in one loop? Thank you in advance! ...

Can I just hand groovy's markupbuilder a node list?

I'm doing some XML processing with groovy. Specifically, I'm inhaling an XML file via XMLParser, doing a whole batch of in-memory processing, and then serializing the resulting data back out to XML via a MarkupBuiler. The vast majority of the data in the file gets transferred to a non-xml based object hierarchy to talk to the gui and h...

Speed of [].forEach.call(... ?

Hi, I'm a big fan of using the forEach method on nodeLists like this: var nodes = document.querySelectorAll(".foo"); [].forEach.call(nodes, function (item) { //do stuff with item }); I was wondering though, does doing it that way take longer than the regular way? e.g. for(var i=0;i<nodes.length;i++){ //do stuff with nodes[i]...

Speeding up xpath

Hello, i have a 1000 entry document whose format is something like <Example> <Entry> <n1></n1> <n2></n2> </Entry> <Entry> <n1></n1> <n2></n2> </Entry> <!--and so on--> There are more than 1000 Entry nodes here. I am writing a Java program which basically gets all the...

Javascript - Concatenate Multiple NodeLists Together

I was originally asking for an elegant way to simulate the Array.concat() functionality in IE or older browsers, because it seemed that concat was not supported. Only, of course it is and the reason the object didn't support it is because it wasn't an array. Oops! getElementsByTagName returns a NodeList, not an array. The real question,...

How to get nodelist using java/XPath in an xml file having namespaces and prefixes

How to get nodelist using XPath with namespaces and prefixes? This java code segment doesnt seem to work. NodeList shows = (NodeList) xPath.evaluate("//ns1:Request", new InputSource(new FileReader("sample.xml")), XPathConstants.NODESET); here's the sample.xml for input: 5ec9d112:1292fffd92a 1 ...

Fastest way to convert JavaScript NodeList to Array?

Previously answered questions here said that this was the fastest way: //nl is a NodeList arr=Array.prototype.slice.call(nl); In benchmarking on my browser I have found that it is more than 3 times slower than this: arr=[]; for(var i=0,n; n=nl[i]; ++i) arr.push(n); They both produce the same output, but I find it hard to believe th...

How to distinguish between live and non-live NodeList collections?

Both document.getElementsByTagName('div') and document.querySelectorAll('div') return NodeList collection. The only difference is that first method returns live-collection and second one - a static one. The question is - is there any opportunity to distinguish one object from another only via inspecting these objects (i.e - not trying t...