You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by "Diez B. Roggisch" <di...@artnology.com> on 2002/09/13 13:37:59 UTC
Turn off entity translation for & and <
Hi,
I searched the list archives and other resources but didn't find a
solution for my problem:
I use xerces SAX2 api to cut an incoming xml stream into chunks,
seperated by certain tags.The resulting chunks then are passed into a
xslt transformation using xalan.The reason for this is that our input
streams can grow up to several 100MB, so our memory is exhausted.
However, the & and < entities are resolved into their characters,
& and <. Currently, I parse every char array passed by the
characters-event and re-insert the entity. This slows down the whole
process a great deal.
Is there a possiblity to turn this behaviour off?
Regards,
Diez
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: Turn off entity translation for & and <
Posted by Elliotte Rusty Harold <el...@metalab.unc.edu>.
At 5:16 PM +0200 9/13/02, Diez B. Roggisch wrote:
>Hmm. Never heard of that before. But your'e right, instead of
>recreating a valid xml document as String, I could try to pass
>through my SAX events. It will introduce some quirks in my current
>application, but at least I'm standard conform then :)
>
It should also speed things up a lot since you don't need to reparse
the document. See
http://www.cafeconleche.org/books/xmljava/chapters/ch17s02.html
--
+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo@metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
| XML in a Nutshell, 2nd Edition (O'Reilly, 2002) |
| http://www.cafeconleche.org/books/xian2/ |
| http://www.amazon.com/exec/obidos/ISBN%3D0596002920/cafeaulaitA/ |
+----------------------------------+---------------------------------+
| Read Cafe au Lait for Java News: http://www.cafeaulait.org/ |
| Read Cafe con Leche for XML News: http://www.cafeconleche.org/ |
+----------------------------------+---------------------------------+
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: Turn off entity translation for & and <
Posted by "Diez B. Roggisch" <di...@artnology.com>.
>
>
>> <foo> bar &baz </foo>
>>
>> I get (as expected)
>>
>> <foo> bar &baz </foo>
>
>
> You get this from what? If you're getting SAX data and you're feeding
> it into an XSLT transform, you should be doing that through TrAX and
> SAXSource, in which case it should all just work. If you're
> reserializing everything first, then your serializer is broken. You do
> have a problem but it is not at all what you think it is.
Hmm. Never heard of that before. But your'e right, instead of recreating
a valid xml document as String, I could try to pass through my SAX
events. It will introduce some quirks in my current application, but at
least I'm standard conform then :)
I'll look into that, thank you.
Diez
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: Turn off entity translation for & and <
Posted by Andy Clark <an...@apache.org>.
Elliotte Rusty Harold wrote:
> Is this really a good thing? I almost always finds code that depends on
> this to be seriously flawed code based on a mistaken notion of how XML
> works.
I don't see it as a problem because these features are
turned off by default. But they exist for those people
that are trying to get as close as possible to round-
tripping their documents because they're writing tools
like editors, etc.
--
Andy Clark * andyc@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: Turn off entity translation for & and <
Posted by Elliotte Rusty Harold <el...@metalab.unc.edu>.
At 12:53 PM +0900 9/15/02, Andy Clark wrote:
>Looking at the docs, though, it appears that these
>features are not documented. Hmmm... I'll have to fix
>that. But here's the features I was talking about:
>
> http://apache.org/xml/features/scanner/notify-char-refs
> http://apache.org/xml/features/scanner/notify-builtin-refs
>
Is this really a good thing? I almost always finds code that depends
on this to be seriously flawed code based on a mistaken notion of how
XML works.
In the case of character references, the SAX LexicalHandler docs
explicitly state "Note also that the boundaries of character
references (which are not really entities anyway) are not reported."
--
+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo@metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
| XML in a Nutshell, 2nd Edition (O'Reilly, 2002) |
| http://www.cafeconleche.org/books/xian2/ |
| http://www.amazon.com/exec/obidos/ISBN%3D0596002920/cafeaulaitA/ |
+----------------------------------+---------------------------------+
| Read Cafe au Lait for Java News: http://www.cafeaulait.org/ |
| Read Cafe con Leche for XML News: http://www.cafeconleche.org/ |
+----------------------------------+---------------------------------+
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: Turn off entity translation for & and <
Posted by Andy Clark <an...@apache.org>.
Joseph Kesselman wrote:
> On the other hand, that's a fairly uncommon request. I'm not sure there'd
> be enough users to justify adding it as a parser feature.
We already have a feature that allows the user to
be notified of the boundaries of entities -- built-in
and character entities. While we don't have a feature
to replace the entity with it's serialized text
(something we're also against), we do allow this much
so that people can use this information to know when
someone wrote a space (" ") versus the character entity
for a space (" "), for example.
Looking at the docs, though, it appears that these
features are not documented. Hmmm... I'll have to fix
that. But here's the features I was talking about:
http://apache.org/xml/features/scanner/notify-char-refs
http://apache.org/xml/features/scanner/notify-builtin-refs
--
Andy Clark * andyc@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: Turn off entity translation for & and <
Posted by Joseph Kesselman <ke...@us.ibm.com>.
Well... The problem is _partly_ as claimed, but that's more a symptom
than a disease.
Officiously, & etc. really are considered "predefined entity
references" (rather than being aliases for the corresponding numeric
character escapes), Most XML parsers assume that folks want these fullly
expanded even when user-supplied entity references aren't. There may or
may not be an argument for suppressing the expansion for peformance
reasons, in some specialized applications.
On the other hand, that's a fairly uncommon request. I'm not sure there'd
be enough users to justify adding it as a parser feature.
And, as we've already noted, the serializer being used is obviously
broken. Suppressing expansion of the entity ref won't help you if the user
chose to write this using a numeric character reference instead!
______________________________________
Joe Kesselman / IBM Research
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: Turn off entity translation for & and <
Posted by Elliotte Rusty Harold <el...@metalab.unc.edu>.
>I'm sorry, but obviously I didn't make my point clear: I want to use
>the SAX event stream as input for another xml parser. So if I
>insert this:
>
Your point is very clear to me. I'm not sure it's clear to you. :-)
><foo> bar &baz </foo>
>
>I get (as expected)
>
><foo> bar &baz </foo>
You get this from what? If you're getting SAX data and you're feeding
it into an XSLT transform, you should be doing that through TrAX and
SAXSource, in which case it should all just work. If you're
reserializing everything first, then your serializer is broken. You
do have a problem but it is not at all what you think it is.
--
+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo@metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
| XML in a Nutshell, 2nd Edition (O'Reilly, 2002) |
| http://www.cafeconleche.org/books/xian2/ |
| http://www.amazon.com/exec/obidos/ISBN%3D0596002920/cafeaulaitA/ |
+----------------------------------+---------------------------------+
| Read Cafe au Lait for Java News: http://www.cafeaulait.org/ |
| Read Cafe con Leche for XML News: http://www.cafeconleche.org/ |
+----------------------------------+---------------------------------+
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: Turn off entity translation for & and <
Posted by Joseph Kesselman <ke...@us.ibm.com>.
>I'm sorry, but obviously I didn't make my point clear: I want to use the
>SAX event stream as input for another xml parser.
To convert the SAX events back into XML for another XML parser, you need
to use an XML serializer -- such as the one that comes packages with
Xerces. One of the things a serializer is responsible for is escaping
characters such '&'.
Yeah, there's a bit of overhead in converting the characters and
converting them back. But that's sorta standard XML processing. You really
want the serializer to do this escaping for you in any case, just in case
some of the other changes you made introduced a character that needs
special treatment.
______________________________________
Joe Kesselman / IBM Research
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: Turn off entity translation for & and <
Posted by "Diez B. Roggisch" <di...@artnology.com>.
Elliotte Rusty Harold wrote:
> At 1:37 PM +0200 9/13/02, Diez B. Roggisch wrote:
>
>
>> However, the & and < entities are resolved into their
>> characters, & and <. Currently, I parse every char array passed by
>> the characters-event and re-insert the entity. This slows down the
>> whole process a great deal.
>>
>> Is there a possiblity to turn this behaviour off?
>>
>
> No, and that's a good thing. Stop reinserting the entity references.
> You don't need to do this, and it's almost certainly introduced bugs
> into your transformation.
I'm sorry, but obviously I didn't make my point clear: I want to use the
SAX event stream as input for another xml parser. So if I insert this:
<foo> bar &baz </foo>
I get (as expected)
<foo> bar &baz </foo>
If I feed that into the next parser, it complains about
org.xml.sax.SAXParseException: The reference to entity "baz" must end
with the ';' delimiter
So - I'll have to rewrite that. Even if I could somehow force xalan
_not_ to fill the whole memory, I afterwards read the transformed xml
into castor, which will bloat things then. So I'm stuck there.
Diez
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: Turn off entity translation for & and <
Posted by Elliotte Rusty Harold <el...@metalab.unc.edu>.
At 1:37 PM +0200 9/13/02, Diez B. Roggisch wrote:
>However, the & and < entities are resolved into their
>characters, & and <. Currently, I parse every char array passed by
>the characters-event and re-insert the entity. This slows down the
>whole process a great deal.
>
>Is there a possiblity to turn this behaviour off?
>
No, and that's a good thing. Stop reinserting the entity references.
You don't need to do this, and it's almost certainly introduced bugs
into your transformation.
--
+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo@metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
| XML in a Nutshell, 2nd Edition (O'Reilly, 2002) |
| http://www.cafeconleche.org/books/xian2/ |
| http://www.amazon.com/exec/obidos/ISBN%3D0596002920/cafeaulaitA/ |
+----------------------------------+---------------------------------+
| Read Cafe au Lait for Java News: http://www.cafeaulait.org/ |
| Read Cafe con Leche for XML News: http://www.cafeconleche.org/ |
+----------------------------------+---------------------------------+
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org