Error parsing data (SAXParser) containing ampersand (&)

K

kebabkongen

Hi,
I am trying to parse some data which is edited with a rich text editor
(FCKeditor)

When I se scandinavian characters, they are converted to html encoded
version by the FCK editor
For example:
"Å" becomes "Å"
"Ø" becomes "Ø"
etc

This content is then sent to the SAX parser as a StringBuffer (sr):
mySaxParser.parse( new InputSource( sr), this);

But with the scandinavian characters I get parsing errors. The input
string:
"Å test"
is converted to
"Å test"
by the FCK editor
And then I get this error from the SAX parser:
WARNING: error parsing text: Å test
org.xml.sax.SAXParseException: The entity "Aring" was referenced, but
not declared.

Is there perhaps some way I should escape the ampersand character?
Or what can I do with the data in the StringBuffer above so that the
parsing will work fine?

Regards, PML
 
K

kebabkongen

Hi again,
I've registered a couple of problems with my post:
(the html coding was rendered as the HTML output, not as the code I
wrote... ;) )

It was supposed to be:

<pre>

"Å" becomes "&Aring"
"Ø" becomes "&Oslash"
etc

....and...

But with the scandinavian characters I get parsing errors. The input
string:
"Å test"
is converted to
"&Aring; test"
by the FCK editor
And then I get this error from the SAX parser:
WARNING: error parsing text: &Aring; test

</pre>

BTW: this is weird;
in preview mode, the post looks fine, but when posted, it seems as if
the coding is rendered as HTML instead as the code I see in preview
mode...
Could it be a bug in google groups? Or how should you post HTML source
code without it being rendered?

Regards, PML
 
K

kebabkongen

....not again...?

Tring once more:

"Å" becomes "&amp;Aring;"
"Ø" becomes "&amp;Oslash"
etc

....and...

But with the scandinavian characters I get parsing errors. The input
string:
"Å test"
is converted to
"&amp;Aring test"
by the FCK editor
And then I get this error from the SAX parser:
WARNING: error parsing text: &amp;Aring; test
org.xml.sax.SAXParseException: The entity "Aring" was referenced, but
not declared.

-PML
 
T

Tor Iver Wilhelmsen

org.xml.sax.SAXParseException: The entity "Aring" was referenced, but
not declared.

You need to tell SAX to ignore unknown entities by adding a handler
for them and let the handler just put the unparsed entity onto
whatever destination you output to. Look at the DTDHandler interface.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top