|Think about Loose Coupling|
XPath to read attributes using XML::LibXML ...by biswanath_c (Beadle)
|on Oct 18, 2009 at 00:35 UTC||Need Help??|
biswanath_c has asked for the
wisdom of the Perl Monks concerning the following question:
I am using XML::LibXML module to parse an XML file and read attributes and node values using XPaths. I am able to read the value of nodes all right; but I am having trouble reading the values of attributes - I am not able to get the right approach (XPath and API to read attributes). Please help.
The sample XML file that I am trying to read:
The PERL script that I am using to read attributes' values :
I am trying to read the value of the attrbbute "attr1" of the node "node1".
When I use XPath "/head/node1/@attr1", I get this result when I try toi run the PERL scri[t shown above:
When I use this XPath - "head/node1/@attr1", I get the same error listed above
When I use this XPath - "head/node1@attr1", the code prints the value of the node node1 and NOT the value of the attribute.
When I use this XPath - "/head/node1@attr1", I get this error: "XPath /head/node1 not found"
So, which Xpath should I use to read the value of the attribute of a node?