--- experimental/server/XMLReader/XMLPacketMaker.java 2000/11/14 10:04:01 1.5 +++ experimental/server/XMLReader/XMLPacketMaker.java 2000/11/14 12:01:19 1.7 @@ -3,11 +3,13 @@ import java.util.ArrayList; import org.xml.sax.*; -import javax.xml.parsers.SAXParserFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +// Paul Mutton, pjm2@ukc.ac.uk +// XMLPacketMaker - Creates an XMLPacket object. public class XMLPacketMaker extends HandlerBase { public XMLPacketMaker () { @@ -38,9 +40,13 @@ public class XMLPacketMaker extends HandlerBase { SAXParser saxParser = factory.newSAXParser(); saxParser.parse(new File(args[0]), new XMLPacketMaker(packet)); - // Print out some things from the packet: - - + // By means of example, print out some things from the packet: - + System.out.println("bung.wibble="+packet.getParam("bung.wibble")); + System.out.println("bung.ping.value1="+packet.getParam("bung.ping.value1")); + // Print out the entire contents of the packet. + packet.printAll(); + } catch (Throwable t) { t.printStackTrace (); } @@ -109,7 +115,7 @@ public class XMLPacketMaker extends HandlerBase { String s = new String(buf, offset, len); if (!s.trim().equals("")) { emit (s); - packet.addParam((String)tagList.get(tagList.size()-1), s); + packet.addParam(getPath(), s); } } @@ -138,5 +144,17 @@ public class XMLPacketMaker extends HandlerBase { } catch (IOException e) { throw new SAXException ("I/O error", e); } + } + + // Return the heirarchical string to be used as a key value + // in the XMLPacket. + private String getPath () { + String path = (String)tagList.get(0); + if (tagList.size() > 0) { + for (int i = 1 ; i < tagList.size() ; i++) { + path = path + "." + (String)tagList.get(i); + } + } + return path; } } \ No newline at end of file