--- experimental/server/XMLReader/XMLPacketMaker.java 2000/11/14 09:48:06 1.4 +++ experimental/server/XMLReader/XMLPacketMaker.java 2000/11/14 10:04:01 1.5 @@ -9,6 +9,16 @@ import javax.xml.parsers.SAXParser; public class XMLPacketMaker extends HandlerBase { + + public XMLPacketMaker () { + // default no-args constructor. + } + + // Constructor for accepting a reference to an XMLPacket + public XMLPacketMaker (XMLPacket packet) { + this.packet = packet; + } + public static void main(String[] args){ if (args.length != 1) { System.err.println ("Usage: cmd filename"); @@ -21,10 +31,16 @@ public class XMLPacketMaker extends HandlerBase { // Set up output stream out = new OutputStreamWriter (System.out, "UTF8"); + // Create the XMLPacket to store values in. + packet = new XMLPacket(); + // Parse the input SAXParser saxParser = factory.newSAXParser(); - saxParser.parse(new File(args[0]), new XMLPacketMaker()); + saxParser.parse(new File(args[0]), new XMLPacketMaker(packet)); + // Print out some things from the packet: - + + } catch (Throwable t) { t.printStackTrace (); } @@ -37,6 +53,7 @@ public class XMLPacketMaker extends HandlerBase { // For storing the tag heirarchy. private ArrayList tagList = new ArrayList(); + static private XMLPacket packet = null; //=========================================================== // SAX DocumentHandler methods @@ -62,6 +79,7 @@ public class XMLPacketMaker extends HandlerBase { public void startElement (String name, AttributeList attrs) throws SAXException { indentLevel++; + tagList.add(name); nl(); emit ("ELEMENT: "); emit ("<"+name); if (attrs != null) { @@ -82,13 +100,17 @@ public class XMLPacketMaker extends HandlerBase { nl(); emit ("END_ELM: "); emit (""); + tagList.remove(tagList.size()-1); indentLevel--; } public void characters (char[] buf, int offset, int len) throws SAXException { nl(); emit ("CHARS: "); String s = new String(buf, offset, len); - if (!s.trim().equals("")) emit (s); + if (!s.trim().equals("")) { + emit (s); + packet.addParam((String)tagList.get(tagList.size()-1), s); + } } //===========================================================