JDOM and false "invalid XML character" problem

I'm using JDOM beta 7, and I have problems building certain XML documents when I try to read them from a URL using

SAXBuilder builder = new SAXBuilder();

document=builder.build(url);

I get an "invalid XML character (Unicode 0x13) was found in the element content of the document" error. However, I'm sure that there is no such character coming from the url -- I tried copying all characters from the stream into a file, and I can then properly do

File xFile = new File("test.xml");

document=builder.build(xFile);

I suspected a problem with conflicting classes from incompatible jar files, but I pulled the latest xerces.jar and crimson.jar from the Apache site, and ran with a specific classpath to make sure I wasn't loading some obsolete class from a different jar, and I still get the error (on certain xml files only).

Does this sound like a bug in the SAX parser, or conflicting libraries? Is there a better SAX parser to try to use?

Thanks in advance,

Rodney

[1043 byte] By [RodLoos] at [2007-9-26 4:38:51]
# 1
Hi Rodney,i had a similar problem. My fault was the used encoding of the xml-file. I had some german special characters in my file and used UTF-8 which is not suitable. I changed to ISO-8859-1. Now it works. Perhaps you have the same problem.
rg021927 at 2007-6-29 17:58:57 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Thanks for the suggestion.

Unfortunately, it didn't fix it, because I don't actually have any invalid characters in the XML. It appears to be a bogus error, but I can't find the real cause of it! I get the error whether I use a SaxBuilder or a DomBuilder within JDOM, but ONLY when I am actully getting the XML from a url. If I read the SAME XML content from a file, I don't get the error.

I even wrote a custom FilterInputStream class to filter out all characters below 0x20 (space) and that still didn't fix it.

Any other suggestions?

RodLoos at 2007-6-29 17:58:57 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

> I'm sure that there is no such character coming from

> the url -- I tried copying all characters from the

> stream into a file

... which does not prove that the encoding of the stream is as expected, does it? What if try to force using the encoding you expect, using something like

InputStreamReader streamReader = new InputStreamReader(inputStream, encoding);

and pass the reader to SAXBuilder.build()?

a.

avbentem at 2007-6-29 17:58:57 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...