[jdom-interest] PATCH: fix for superfluous newline bug

guru at stinky.com guru at stinky.com
Sun Jun 17 08:26:33 PDT 2001


I've made other changes, and my laptop's network drivers stopped
working, so I can't give you an accurate line number.

If you want to make the patch yourself, here are instructions:

XMLOutputter.java, method printElementContent, in the "not stringOnly"
case:

after 

if (content instanceof String) {
  String scontent = (String) content;

insert:

	// bugfix: don't print lines for whitespace that's
	// only sticking between close tags
	if (textNormalize && isWhitespace(scontent)) {
		wasFullyWhite = true;
		continue;
	}


also add the function:

protected boolean isWhitespace(String s) {
	char[] c = s.toCharArray();
	for (int i=0; i<c.length; ++i) {
		if (" \t\n\r".indexOf(c[i]) == -1) {
			return false;
		}
	}
}

---

My test cases ran OK, but you should make sure your favorite documents
come out right.  In particular, look at cases with mixed text and
element content, like "<p>my <b>dog</b> has fleas</p>"

BTW, that case doesn't quite work, since padText functionality has
been removed, but that's a different bug.


-- 
Alex Chaffee                       mailto:alex at jguru.com
jGuru - Java News and FAQs         http://www.jguru.com/alex/
Creator of Gamelan                 http://www.gamelan.com/
Founder of Purple Technology       http://www.purpletech.com/
Curator of Stinky Art Collective   http://www.stinky.com/



More information about the jdom-interest mailing list