Update the output of the reference implementation to the new format.
[tatoo.git] / tools / XPathEval.java
index 8c854ac..8ce8db1 100644 (file)
@@ -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("<xml_result>");
+      startTime = System.nanoTime();
+      System.out.println("<xml_result num=\"1\">");
       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("</xml_result>");
+      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) {