Merge branch 'feature/test-suite'
[tatoo.git] / tools / XPathEval.java
1 import javax.xml.xpath.*;
2 import org.xml.sax.*;
3 import org.w3c.dom.*;
4 import javax.xml.transform.*;
5 import javax.xml.transform.dom.*;
6 import javax.xml.transform.stream.*;
7
8 public class XPathEval {
9
10
11   public static void main(String args[]) {
12     try {
13
14
15       XPath xpath = XPathFactory.newInstance().newXPath();
16       String expression = args[1];
17       InputSource inputSource = new InputSource(args[0]);
18       NodeList nodes = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET);
19       Transformer serializer = TransformerFactory.newInstance().newTransformer();
20       serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
21       StreamResult o = new StreamResult(System.out);
22       System.out.println("<xml_result>");
23       for(int i = 0; i < nodes.getLength(); i++){
24         serializer.transform(new DOMSource(nodes.item(i)), o);
25         System.out.println("");
26       };
27       System.out.println("</xml_result>");
28     } catch (XPathException e) {
29       System.out.println (e.getCause());
30     } catch (Exception e) {
31       System.out.println(e);
32     };
33
34
35   }
36 }