tags:

views:

190

answers:

4

Which is better to use when iterating over DOM elements or finding a a set of DOM elements. is Xpath faster?

A: 

Xpath is more clean.

EDIT: Sorry, I don't know if it is faster.

Aito
thanks for your input
aaron
A: 

If you want to find a group of elements that are at different hiearchical levels and different attributes of interest then you should use Xpath.

If you just want to "iterate" one by one over a set of elements then just use the iterator.

Harley Green
thanks! appreciate your time
aaron
A: 

The dojo team did some research about when XPath is faster for their dojo.query interface.

See their Blog Post about it.

Kyle Butt
A: 

according to this post "The DOM traversal code is about four times faster than the XPath code." http://www.sklar.com/blog/archives/85-Speed-DOM-traversal-vs.-XPath-in-PHP-5.html

schrödinger