You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by ni...@caramail.com on 2001/01/19 15:52:05 UTC
SAX exception with '&' char
In order to create a PDF file, I use a xml file coming from
an other source and look like this :
<TAG>mon texte avec accent à pour tester</TAG>
or like this :
<TAG>The society Marcel & Co</TAG>
or
<TAG>The society Marcel &Co</TAG>
The problem appears with the '&' char. So is there any
solution to get the text between the tag, without any text
modification because we don't create this file ?
We must handle any of these cases.
Here are the corrresponding exceptions :
org.xml.sax.SAXParseException: The entity "agrave" was
referenced, but not declared.
org.xml.sax.SAXParseException: The entity name must
immediately follow the '&' in the entity reference.
org.xml.sax.SAXParseException: The reference to entity "Co"
must end with the ';' delimiter.
Thanks a lot for any solution.
Nicolas.
A bient�t.
Nicolas.
______________________________________________________
Bo�te aux lettres - Caramail - http://www.caramail.com
Re: SAX exception with '&' char
Posted by Klaus Malorny <Kl...@knipp.de>.
nicolas.tisserand@caramail.com wrote:
>
> In order to create a PDF file, I use a xml file coming from
> an other source and look like this :
>
> <TAG>mon texte avec accent à pour tester</TAG>
>
> or like this :
>
> <TAG>The society Marcel & Co</TAG>
>
> or
>
> <TAG>The society Marcel &Co</TAG>
>
> The problem appears with the '&' char. So is there any
> solution to get the text between the tag, without any text
> modification because we don't create this file ?
> We must handle any of these cases.
>
> Here are the corrresponding exceptions :
>
> org.xml.sax.SAXParseException: The entity "agrave" was
> referenced, but not declared.
>
> org.xml.sax.SAXParseException: The entity name must
> immediately follow the '&' in the entity reference.
>
> org.xml.sax.SAXParseException: The reference to entity "Co"
> must end with the ';' delimiter.
>
> Thanks a lot for any solution.
> Nicolas.
>
> A bientôt.
>
> Nicolas.
> ______________________________________________________
> Boîte aux lettres - Caramail - http://www.caramail.com
>
You got these exceptions just because your XML code is invalid. So it's not a
problem of the parser. The '&' has, like in HTML, a special meaning, it is the
beginning of an entity reference. So the parser expects either a name or a
number (starting with a '#'), followed by a semicolon.
There are only five predefined names:
& &
" "
' '
< <
> >
all other names must be defined by a DTD. As probably you don't have a DTD,
there is no definition for "agrave" and the parser fails.
Numeric character entities (hopefully the right term) contain the character
code of the corresponding Unicode character. For an "agrave" you should either
write
à or à (the latter is the hexadecimal variant)
You should read the XML specification for details. Regarding to your problem,
the only way is to make your XML code valid, e.g. by preprocessing the data.
regards
Klaus Malorny
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
For additional commands, email: fop-dev-help@xml.apache.org
Re: SAX exception with '&' char
Posted by Damien Gardner <dg...@itdesign.ie>.
At 19/01/01 14:59 Friday, you wrote:
>In order to create a PDF file, I use a xml file coming from
>an other source and look like this :
>
><TAG>mon texte avec accent à pour tester</TAG>
>
>or like this :
>
><TAG>The society Marcel & Co</TAG>
>
>or
>
><TAG>The society Marcel &Co</TAG>
>
>
>The problem appears with the '&' char. So is there any
>solution to get the text between the tag, without any text
>modification because we don't create this file ?
>We must handle any of these cases.
>
>Here are the corrresponding exceptions :
>
>org.xml.sax.SAXParseException: The entity "agrave" was
>referenced, but not declared.
>
>org.xml.sax.SAXParseException: The entity name must
>immediately follow the '&' in the entity reference.
>
>org.xml.sax.SAXParseException: The reference to entity "Co"
>must end with the ';' delimiter.
None of the examples you provide are well-formed XML so
they cannot be parsed. For the first, you need a DTD
that defines the "agrave" entity, as this is not one of
the predefined entities in XML. For the second, you
must use:
<TAG>The society Marcel & Co</TAG>
and for the third:
<TAG>The society Marcel &Co</TAG>
While you don't create the file, you might request that
you be sent well-formed XML. If there are errors in what
is sent to you, you can only complain to the sender, or
fix the errors in their XML.
It may be that the originators of the documents do not
know their HTML from their XML. The entity "agrave" is
valid in HTML as is the use of the ampersand (&) as shown
but neither are valid in XML.
It's a bit like being sent Java code with syntax errors
in it and then trying to find a compiler that won't
complain about them and will magically figure out what
the code was meant to be. You will just have to modify
the code to fix it or write your own parser!
Sorry,
Damien.
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
For additional commands, email: fop-dev-help@xml.apache.org