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

antony at n-space.com.au antony at n-space.com.au
Thu Feb 1 23:33:38 PST 2001


Many (most?) applications wouldn't care, but technically this solution
is erroneous - PI's and comments can appear after the final tag - see
section 2.1 of the XML 1.0 spec.

> From: "Tony Montgomery Smith" <tonyms at compuserve.com>
> To: <jdom-interest at jdom.org>
> Date: Thu, 1 Feb 2001 09:35:18 -0000
> Subject: [jdom-interest] Why does passing a document through a socket sometimes hang the parser?
> 
> 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 -
> http://xml.apache.org/xerces-j/faq-write.html#faq-11
> 
> 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;
>         ++level;
> .
> .
>     public void endElement(String namespaceURI, String localName,
>                            String rawName) throws SAXException {
> 
>         --level;
>         if (firstTag.equals(localName) || (level == 0))
>           throw new SAXException("Finished");

---  Antony Blakey     mailto:antony at n-space.com.au  ---
---  N-Space Pty Ltd   http://www.n-space.com.au     ---
---  Sydney: 02 9212 6445  Adelaide: 08 8359 2470    ---

There are two ways of constructing a software design: One
way is to make it so simple that there are obviously no
deficiencies, and the  other way is to make it so
complicated that there are no obvious deficiencies. The
first method is far more difficult.
   - C.A.R. Hoare



More information about the jdom-interest mailing list