in reply to XPath with node names and attributes...

Just give the XPath engine properly formatted XPath queries and all will work.

In your case, that likely means using:

root/head/node1@att1

instead of

root/head/node1/@att1

Replies are listed 'Best First'.
Re^2: XPath with node names and attributes...
by mirod (Canon) on Oct 16, 2009 at 16:17 UTC

    There must be something I am missing here. root/head/node1@att1 is invalid, while root/head/node1/@att1 works just fine. I tested that with several tools, including XML::LibXML.

    I would actually had the starting slash: /root/head/node1@att1.

Re^2: XPath with node names and attributes...
by biswanath_c (Beadle) on Oct 16, 2009 at 16:05 UTC

    I tried using the XPath that you suggested (root/head/node1@att1). But in that case, i call findnodes(<XPath with attribute>) and iterate thru the resulting array and call findValue(".") on the array elements, it returns nothing! i tried calling nodeValue() also, that too returned nothing! i tried textContent(), it returned value of the node but not the value of the attribute!

    What do i do?

      Actually, I am wrong and you are right - queries for attributes also need / as the separator. I thought the @ would separate a element node from an attribute node, as the documentation seems to suggest to me in //title[@lang], but upon actually trying it, I find that only node/@attribute works for me, and likely is the correct query to use.