X-Git-Url: http://git.nguyen.vg/gitweb/?p=tatoo.git;a=blobdiff_plain;f=tools%2FXPathEval.java;fp=tools%2FXPathEval.java;h=8c854ac77ffe849e358fec2d4e1613995a01a6eb;hp=0000000000000000000000000000000000000000;hb=37e8a9fe5d5f1f430ced3aa65daf572d330d3398;hpb=f8bc3114d2f36de5f743a7f6695b2353090f7e36 diff --git a/tools/XPathEval.java b/tools/XPathEval.java new file mode 100644 index 0000000..8c854ac --- /dev/null +++ b/tools/XPathEval.java @@ -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(""); + for(int i = 0; i < nodes.getLength(); i++){ + serializer.transform(new DOMSource(nodes.item(i)), o); + System.out.println(""); + }; + System.out.println(""); + } catch (XPathException e) { + System.out.println (e.getCause()); + } catch (Exception e) { + System.out.println(e); + }; + + + } +}