Try with this:
//prediction/@seconds
The double /
selects all rows while the @
select the attribute you want. Your query returns nothing because you are trying to get the seconds
attribute of direction
which of course is non existent.
Question
I'm trying to parse an XML file that looks like this:
<body>
<predictions>
<direction>
<prediction epochTime="1400182631361" seconds="1109" minutes="18" isDeparture="false" dirTag="N__OB1" vehicle="1495" vehiclesInConsist="2" block="9708" tripTag="6041030"/>
<prediction epochTime="1400182942181" seconds="1420" minutes="23" isDeparture="false" dirTag="N__OB1" vehicle="1515" vehiclesInConsist="2" block="9709" tripTag="6041031"/>
<prediction epochTime="1400183687220" seconds="2165" minutes="36" isDeparture="false" dirTag="N__OB1" vehicle="1481" vehiclesInConsist="2" block="9710" tripTag="6041032"/>
<prediction epochTime="1400183966372" seconds="2444" minutes="40" isDeparture="false" affectedByLayover="true" dirTag="N__OB1" vehicle="1520" vehiclesInConsist="2" block="9712" tripTag="6041033"/>
<prediction epochTime="1400184566372" seconds="3044" minutes="50" isDeparture="false" affectedByLayover="true" dirTag="N__OB1" vehicle="1430" vehiclesInConsist="2" block="9713" tripTag="6041034"/>
</direction>
</predictions>
</body>
I'd like to extract all the seconds
attributes inside each prediction
node with Xpath (via "/body/predictions/direction/@seconds"), but it's not returning anything for me. Any ideas?
Solution
Try with this:
//prediction/@seconds
The double /
selects all rows while the @
select the attribute you want. Your query returns nothing because you are trying to get the seconds
attribute of direction
which of course is non existent.