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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert BormansInformation 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lucavillaAuthor Commented:
Fantastic answer! thanks!   A+++++
Geert BormansInformation ArchitectCommented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.