/*
 * Created on 13.11.2003
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package de.kksoftware.demo.xml;

import java.io.*;
import java.util.*;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.xpath.XPath;

/**
 * @author administrator
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class JDomReadXPath {

	public static void main(String[] args) throws Exception {
		if (args.length!=1){
			System.out.println("Usage: JDomReadXPath <path>");
			System.exit(1);
		}
		String strXPathExpression = args[0];
		
		// create a XML parser and read the XML file
		SAXBuilder oBuilder = new SAXBuilder();
		Document oDoc = oBuilder.build(new File("myconfig.xml"));

		XPath oPath = XPath.newInstance(strXPathExpression);
		List oResult = oPath.selectNodes(oDoc);
		Iterator iter = oResult.iterator();
		while (iter.hasNext()) {
			Element oNode = (Element) iter.next();
			System.out.println("Found: "+oNode.getName());
		}
	}
}

