[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] SAX drivers bug ... or feature !
Hi, I think there is a little problem with AttributeList implementation within some of the SAX drivers (i have tested the following code with my SXP SAX driver, the XML4J SAX driver and the AELFRED SAX driver. We are all giving the same results (gosh...). This code should write the size of each AttributeList that has been read by the parser when it reached the end of the Document. But it always prints the size of the last AtributeList found. Bug or feature ? Pat. /* * @(#) saxbug.java * * Copyright 1998 (C) PATRICE BONHOMME * UMR LORIA (Universities of Nancy, CNRS & INRIA) * */ import org.xml.sax.*; import org.xml.sax.helpers.*; import java.util.Vector; /** * SAX demonstration. * * * @version * @author Patrice Bonhomme, bonhomme@l... */ public class saxbug extends org.xml.sax.HandlerBase { public static void main (String args[] ) throws Exception { saxbug demo = new saxbug(); Parser parser = null; try { // try to create a SAX parser parser = ParserFactory.makeParser(); System.out.println(parser); parser.setDocumentHandler(demo); } catch (ClassNotFoundException e) { System.err.println("SAX parser class cannot be loaded."); System.exit(1); } catch (IllegalAccessException e) { System.err.println("SAX parser class does not have a zero-argument constructor."); System.exit(1); } catch (InstantiationException e) { System.err.println("SAX parser class cannot be instantiated."); System.exit(1); } for (int i = 0; i < args.length; i++) { System.out.println("parsing => " + args[i]); try { parser.parse(args[i]); } catch(Exception e) { System.out.println(e.getMessage()); } } } // HandlerBase methods overriding public void setDocumentLocator (Locator locator) { } Vector attrs; /** * @see org.xml.sax.DocumentHandler#startDocument */ public void startDocument () { attrs = new Vector(); } /** * Print the size of each AttributeList within the Vector <code>attrs</code> * @see org.xml.sax.DocumentHandler#endDocument */ public void endDocument () { int j = 0; for (java.util.Enumeration e = attrs.elements(); e.hasMoreElements();j++) { AttributeList attlist = (AttributeList)e.nextElement(); System.out.println("size of attlist(" + j +")=" + ((AttributeList)attlist).getLength()); } } /** * Add the AttributeList to the Vector <code>attrs</code>. * * @see org.xml.sax.DocumentHandler#startElement */ public void startElement (String name, AttributeList attributes) { System.out.println("Start element: " + name + " size of attlist=" + attributes.getLength()); attrs.addElement(attributes); } /** * @see org.xml.sax.DocumentHandler#endElement */ public void endElement (String name) { } /** * @see org.xml.sax.DocumentHandler#characters */ public void characters (char ch[], int start, int length) { } /** * @see org.xml.sax.DocumentHandler#ignorableWhitespace */ public void ignorableWhitespace (char ch[], int start, int length) { } /** * @see org.xml.sax.DocumentHandler#processingInstruction */ public void processingInstruction (String target, String data) { } // DTD Handler implementation /** * @see org.xml.sax.DTDHandler#unparsedEntityDecl */ public void unparsedEntityDecl (String name, String publicId, String systemId, String notationName) { } } // EOF -- ============================================================== bonhomme@l... | Office : B.228 http://www.loria.fr/~bonhomme | Phone : 03 83 59 30 52 -------------------------------------------------------------- * Serveur Silfide : http://www.loria.fr/projets/Silfide * Projet Aquarelle : http://aqua.inria.fr ============================================================== xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@i... Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ To (un)subscribe, mailto:majordomo@i... the following message; (un)subscribe xml-dev To subscribe to the digests, mailto:majordomo@i... the following message; subscribe xml-dev-digest List coordinator, Henry Rzepa (mailto:rzepa@i...)
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|