I have a file with the following structure
<admin>
<sampleName>Willow oak leaf</sampleName>
<sampleDescription comment="Total genes">
<cvParam cvLabel="Bob" accession="123" name="Oak" />
</sampleDescription>
</admin>
I’m trying to get out the text “Total genes” after the sampleDescription comment, and I have used the following code:
sampleDescription = doc.xpath( "/admin/Description/@comment" )
sampleDescription = doc.xpath( "/admin/Description" ).text
But neither work. What am I missing?
doc.xpathreturns a NodeSet which acts a bit like an array. So you need to grab the first elementYou could also use
at_xpathwhich is equivalent toxpath(foo).firstAnother thing to note is that attributes on nodes are accessed like hash elements–with
[<key>]