Adds a set of testing script:
[tatoo.git] / tools / XPathEval.java
diff --git a/tools/XPathEval.java b/tools/XPathEval.java
new file mode 100644 (file)
index 0000000..8c854ac
--- /dev/null
@@ -0,0 +1,36 @@
+import javax.xml.xpath.*;
+import org.xml.sax.*;
+import org.w3c.dom.*;
+import javax.xml.transform.*;
+import javax.xml.transform.dom.*;
+import javax.xml.transform.stream.*;
+
+public class XPathEval {
+
+
+  public static void main(String args[]) {
+    try {
+
+
+      XPath xpath = XPathFactory.newInstance().newXPath();
+      String expression = args[1];
+      InputSource inputSource = new InputSource(args[0]);
+      NodeList nodes = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET);
+      Transformer serializer = TransformerFactory.newInstance().newTransformer();
+      serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+      StreamResult o = new StreamResult(System.out);
+      System.out.println("<xml_result>");
+      for(int i = 0; i < nodes.getLength(); i++){
+        serializer.transform(new DOMSource(nodes.item(i)), o);
+        System.out.println("");
+      };
+      System.out.println("</xml_result>");
+    } catch (XPathException e) {
+      System.out.println (e.getCause());
+    } catch (Exception e) {
+      System.out.println(e);
+    };
+
+
+  }
+}