Guest User

Untitled

a guest
Jun 24th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. import org.jdom.*;
  2. import org.jdom.input.SAXBuilder;
  3. import org.jdom.xpath.XPath;
  4.  
  5. import java.io.IOException;
  6. import java.util.List;
  7.  
  8.  
  9. /**
  10. * Created by IntelliJ IDEA.
  11. * User: jeroen
  12. * Date: 22-feb-2011
  13. * Time: 15:57:59
  14. * To change this template use File | Settings | File Templates.
  15. */
  16. public class XML {
  17.  
  18. public void toon(){
  19. SAXBuilder parser = new SAXBuilder();
  20. Document document = null;
  21. try {
  22. document = parser.build("./bars.xml");
  23. //XPath xPath = XPath.newInstance("//y-axis-title"); oef 1.1
  24. //XPath xPath = XPath.newInstance("//bars/bar[@number = 4]");
  25. //XPath xPath = XPath.newInstance("//bar[@number = 5]");
  26. XPath xPath = XPath.newInstance("//article[@code = 13549014]/harvest_time");
  27. List<Element> elements = xPath.selectNodes(document);
  28.  
  29. System.out.println(elements.size());
  30. for(Element element : elements){
  31. System.out.println(element.getValue());
  32. }
  33. } catch (JDOMException e) {
  34. System.out.println("");
  35. } catch (IOException e) { }
  36. System.out.println("");
  37. }
  38. }
Add Comment
Please, Sign In to add comment