[jdom-interest] Why does passing a document through a socket sometimes hang the parser?

Tony Montgomery Smith tonyms at compuserve.com
Thu Feb 1 01:35:18 PST 2001

A relevant problem, though it is not necessarily the cause here, is that the
Xerces SAX parser doesn't work properly on socket input. My suggested
workarounds are in the updated FAQ -

This solution requires throwing a "finished" exception on logical EOF, rather
than trying to find a physical EOF, which obviously isn't there for a socket.
I've had to modify org.jdom.SAXBuilder as follows:

class SAXHandler extends DefaultHandler implements LexicalHandler {
    /** New variables used to discover the logical end of the document */
    private int level;
    private String firstTag;
    public void startElement(String namespaceURI, String localName,
                             String qName, Attributes atts) throws SAXException

        if (level == 0)
          firstTag = localName;
    public void endElement(String namespaceURI, String localName,
                           String rawName) throws SAXException {

        if (firstTag.equals(localName) || (level == 0))
          throw new SAXException("Finished");

Tony Montgomery-Smith

More information about the jdom-interest mailing list