[jdom-interest] encoding problem converting XML document to string
Bradley S. Huffman
hip at cs.okstate.edu
Thu Nov 6 07:41:07 PST 2003
"William Krick" writes:
> Thanks for your help.
>
> Unfortunately, setTextNormalize isn't supported in my version of JDOM
>
> What I really need is to go from human readable formatted XML
> ASCII file to an XML string with no whitespace.
>
> The steps in between are not really important to me.
>
> I may end up having to skip the JDOM all together and just read the file a
> line at a time, trim leading and trailing whitespace, and append it to a
> string buffer.
Hmmm, a workaround might be to subclass SAXHandler with a new characters
method, something like
void characters(char[] ch, int start, int len) {
char[] new_ch;
// Copy ch to new_ch trimming whitespace
.
.
.
// Call super
super.characters(new_ch, new_start, new_len);
}
But I cann't remember if all versions of SAXBuilder allow plugging in a custom
SAXHandler.
The only problem this might have is SAX allows a chunk of text to be broken
up into several calls to characters. But if you text strings are short, a
few hundred chars, you should be all right.
Brad
More information about the jdom-interest
mailing list