Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java xpath selection

Tags:

java

xpath

I'm having a little trouble getting values out of an XML document. The document looks like this:

<marketstat>  

<type id="35"> 
  <sell> 
    <median>6.00</median>  
  </sell> 
</type>  

<type id="34">    
  <sell> 
    <median>2.77</median> 
  </sell> 
</type>      

</marketstat> 

I need to get the median where type = x.

I've always had trouble figuring out xpath with Java and I can never find any good tutorials or references for this. If anyone could help me figure this out that would be great.

like image 439
Travis Avatar asked Aug 18 '26 08:08

Travis


1 Answers

For the XPATH side of the problem: this should do the trick

//*/type[@id='34']/*/median

When I am dealing with XPATH I usually use W3Schools as reference. And IBM DeveloperWorks has a tutorial for the Java XPath API

like image 105
cmaderthaner Avatar answered Aug 20 '26 22:08

cmaderthaner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!