[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

SAX drivers bug ... or feature !

  • From: Patrice Bonhomme <Patrice.Bonhomme@l...>
  • To: "XML Developers' List" <xml-dev@i...>
  • Date: Wed, 18 Nov 1998 16:23:04 +0100

sax parser driver

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!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.