[jdom-interest] Bug in SAXHandler: ignorable white space is thrown away

Elliotte Rusty Harold elharo at metalab.unc.edu
Mon Apr 30 12:11:44 PDT 2001


The SAXHandler class used by SAXBuilder does not override this SAX
method:

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws SAXException

This means that text nodes contained entirely of ignorable white space
are thrown away. For example, when given this document

<?xml version="1.0"?>
<!DOCTYPE TEAM SYSTEM "team.dtd">
<TEAM xmlns:xinclude="http://www.w3.org/1999/XML/xinclude">
  <TEAM_CITY>New York</TEAM_CITY>
  <TEAM_NAME>Mets</TEAM_NAME>
</TEAM>

JDOM actually sees it as this document:

<?xml version="1.0"?>
<!DOCTYPE TEAM SYSTEM "team.dtd">
<TEAM
xmlns:xinclude="http://www.w3.org/1999/XML/xinclude"><TEAM_CITY>New
York</TEAM_CITY><TEAM_NAME>Mets</TEAM_NAME></TEAM>

This is not the behavior I need and not I think the default behavior
JDOM should use. It's most important for formatting, but it's not just a
formatting issue. This bug means that when a document is built using
SAX, it's missing some of the text nodes it should have. 

For various technical reasons, white space nodes are only considered
ignorable in the presence of a DTD, so you'll only see this bug in valid
documents. 

DOMBuilder exhibits this bug as well, though I'm not sure why. 

-- 
+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+ 
|               Java I/O (O'Reilly & Associates, 1999)               |
|            http://metalab.unc.edu/javafaq/books/javaio/            |
|   http://www.amazon.com/exec/obidos/ISBN=1565924851/cafeaulaitA/   |
+----------------------------------+---------------------------------+
|  Read Cafe au Lait for Java News:  http://metalab.unc.edu/javafaq/ | 
|  Read Cafe con Leche for XML News: http://metalab.unc.edu/xml/     |
+----------------------------------+---------------------------------+



More information about the jdom-interest mailing list