X-Git-Url: http://git.nguyen.vg/gitweb/?p=tatoo.git;a=blobdiff_plain;f=tools%2FXPathEval.java;h=8ce8db1f15d7368d3a4007d81ea22932603cf194;hp=8c854ac77ffe849e358fec2d4e1613995a01a6eb;hb=4c1c49168a2ff5841a1d4fe26f99ca2776bc5a58;hpb=37e8a9fe5d5f1f430ced3aa65daf572d330d3398 diff --git a/tools/XPathEval.java b/tools/XPathEval.java index 8c854ac..8ce8db1 100644 --- a/tools/XPathEval.java +++ b/tools/XPathEval.java @@ -15,16 +15,30 @@ public class XPathEval { XPath xpath = XPathFactory.newInstance().newXPath(); String expression = args[1]; InputSource inputSource = new InputSource(args[0]); + long startTime = System.nanoTime(); NodeList nodes = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET); + long evalTime = (System.nanoTime() - startTime) / 1000000; Transformer serializer = TransformerFactory.newInstance().newTransformer(); serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); StreamResult o = new StreamResult(System.out); - System.out.println(""); + startTime = System.nanoTime(); + System.out.println(""); for(int i = 0; i < nodes.getLength(); i++){ - serializer.transform(new DOMSource(nodes.item(i)), o); - System.out.println(""); + Node n = nodes.item(i); + switch (n.getNodeType()) { + case Node.ATTRIBUTE_NODE: + System.out.print (n.getNodeName() + "=" + n.getNodeValue()); + break; + default: + serializer.transform(new DOMSource(nodes.item(i)), o); + break; + }; + System.out.println(); }; System.out.println(""); + long printTime = (System.nanoTime() - startTime) / 1000000; + System.err.println("evaluation time: " + evalTime + "ms"); + System.err.println("serialization time: " + printTime + "ms"); } catch (XPathException e) { System.out.println (e.getCause()); } catch (Exception e) {