XPath for extracting all the element+attribute nodes

This is my XML test text:
"<memo author="Pat Coleman"><to>Carole Poland</to></memo>"

How can I get with XPath/XML DOM a node-set containing all the element and attribute nodes?

is   $obj.selectNodes('//@*|//*')   the shortest/most efficient solution?
Who is Participating?
Geert BormansConnect With a Mentor Information ArchitectCommented:
This question can not be answered without context


is likely the "shortest" solution in terms of XPath clarity and consiseness

However, I don't think I would ever do that without knowing at least a little about the optimisations going on inside the processor. A naive processor would walk the three twice, once for the elements and once for the attributes

If this were a XPath2 processor, I would do something like
$obj.selectNodes('//node()/(self::* | @*)')
to force into only one tree-walk regardless of processor optimisations

the save approach would be
then iterate the array, and for each node add the getAttributes
If you ask for efficiency, that will almost always beat it
lucavillaAuthor Commented:
Fantastic answer! thanks!   A+++++
Geert BormansInformation ArchitectCommented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.