dleslie 00/11/20 04:59:41
Modified: java/samples/ApplyXPath ApplyXPath.java
Log:
Updated to use new TrAX. Doesn't really work with new Serializer!
Revision Changes Path
1.10 +20 -16 xml-xalan/java/samples/ApplyXPath/ApplyXPath.java
Index: ApplyXPath.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/samples/ApplyXPath/ApplyXPath.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ApplyXPath.java 2000/10/25 17:49:15 1.9
+++ ApplyXPath.java 2000/11/20 12:59:41 1.10
@@ -79,12 +79,15 @@
import javax.xml.parsers.ParserConfigurationException;
// Imported Serializer classes
-import org.apache.serialize.OutputFormat;
-import org.apache.serialize.Serializer;
-import org.apache.serialize.SerializerFactory;
-import org.apache.xml.serialize.transition.XMLSerializer;
-import org.apache.xml.serialize.transition.TextSerializer;
+import org.apache.xalan.serialize.OutputFormat;
+import org.apache.xalan.serialize.Serializer;
+import org.apache.xalan.serialize.SerializerFactory;
+import org.apache.xalan.serialize.DOMSerializer;
+import org.apache.xalan.serialize.Method;
+//import org.apache.xalan.serialize.FormatterToXML;
+//import org.apache.xalan.serialize.helpers.XMLOutputFormat;
+
/**
* Very basic utility for applying an XPath epxression to an xml file and
printing information
/ about the execution of the XPath object and the nodes it finds.
@@ -125,7 +128,7 @@
try
{
DocumentBuilderFactory dfactory =
DocumentBuilderFactory.newInstance();
- DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
+ DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
doc = docBuilder.parse(in);
}
catch (ParserConfigurationException pce)
@@ -143,23 +146,24 @@
{
// Use the simple XPath API to select a nodeIterator.
nl = XPathAPI.selectNodeIterator(doc, xpath);
- }
+ }
catch (Exception e2)
{
System.err.println("selectNodeIterator threw: " + e2.toString() + "
perhaps your xpath didn't select any nodes");
e2.printStackTrace();
return;
}
- XMLSerializer xmlser = new XMLSerializer(System.out, new
OutputFormat());
- Node n = null;
- try
- {
- while ((n = nl.nextNode())!= null)
- {
- xmlser.serializeXPathReturnNode(n);
- }
+ try
+ {
+ Serializer ser = SerializerFactory.getSerializer(Method.XML);
+ DOMSerializer domser = ser.asDOMSerializer();
+ Node n = null;
+ while ((n = nl.nextNode())!= null)
+ {
+ domser.serialize(n);
+ }
}
- catch (Exception e3)
+ catch (Exception e3)
{
e3.printStackTrace();
return;