Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.jdom.*;
- import org.jdom.input.SAXBuilder;
- import org.jdom.xpath.XPath;
- import java.io.IOException;
- import java.util.List;
- /**
- * Created by IntelliJ IDEA.
- * User: jeroen
- * Date: 22-feb-2011
- * Time: 15:57:59
- * To change this template use File | Settings | File Templates.
- */
- public class XML {
- public void toon(){
- SAXBuilder parser = new SAXBuilder();
- Document document = null;
- try {
- document = parser.build("./bars.xml");
- //XPath xPath = XPath.newInstance("//y-axis-title"); oef 1.1
- //XPath xPath = XPath.newInstance("//bars/bar[@number = 4]");
- //XPath xPath = XPath.newInstance("//bar[@number = 5]");
- XPath xPath = XPath.newInstance("//article[@code = 13549014]/harvest_time");
- List<Element> elements = xPath.selectNodes(document);
- System.out.println(elements.size());
- for(Element element : elements){
- System.out.println(element.getValue());
- }
- } catch (JDOMException e) {
- System.out.println("");
- } catch (IOException e) { }
- System.out.println("");
- }
- }
Add Comment
Please, Sign In to add comment