You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Chris Jenkins <cj...@nfld.com> on 2000/06/16 18:35:55 UTC
Ampersand problem.
Hi,
I'm using the org.apache.xerces.parsers.DOMParser to parse a simple xml
string that has an internal DTD.
It seems that if there is an & in a node, it appears to truncate the
tag's data up to the ampersand.
So <mytag>blah&moretext</mytag> seems to only contain "blah". I even
went so far as to set the feature for the general entities to "true".
Someone on the mailing list suggested that the parser creates 3 child nodes,
with text:
1. blah
2. &
3.moretext
instead of 1 tag with data "blah&moretext". I don't believe this was
released with such a very serious flaw, especially when the previous version
com.ibm.xml.parser.Parser didn't have this problem.
Could you please clarify this issue for me?
Much thanks,
Chris Jenkins
Re: Ampersand problem.
Posted by Mike Pogue <mp...@apache.org>.
I believe this is not a "serious flaw", if you read the DOM spec carefully.
You can use normalize() to get the strings the way I suspect you want them.
Mike
Chris Jenkins wrote:
>
> Hi,
>
> I'm using the org.apache.xerces.parsers.DOMParser to parse a simple xml
> string that has an internal DTD.
>
> It seems that if there is an & in a node, it appears to truncate the
> tag's data up to the ampersand.
> So <mytag>blah&moretext</mytag> seems to only contain "blah". I even
> went so far as to set the feature for the general entities to "true".
>
> Someone on the mailing list suggested that the parser creates 3 child nodes,
> with text:
> 1. blah
> 2. &
> 3.moretext
>
> instead of 1 tag with data "blah&moretext". I don't believe this was
> released with such a very serious flaw, especially when the previous version
> com.ibm.xml.parser.Parser didn't have this problem.
>
> Could you please clarify this issue for me?
>
> Much thanks,
> Chris Jenkins
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
Re: Ampersand problem.
Posted by Mike Pogue <mp...@apache.org>.
Version 3 of the IBM parser became the initial code base for Xerces-J.
Version 2, although freely available on Alphaworks, was never published
as a version of Xerces-J...
Andy, hey, did you have a chance to look at this one again? (I know
he's knee deep in Schema right now...)
Mike
Ryan Schmidt wrote:
>
> Mike Pogue wrote:
> >
> > OK, sorry...if it was already agreed that this is a bug...
>
> You might be right about the multiple text nodes being part of the DOM
> spec (I'm not familiar with it). The bug was in the normalization.
>
> > Do you remember who said they would put in a fix?
>
> It was Andy Clark who suggested I write one. The first one I submitted
> wasn't quite right, and there was no reply (on the list) to the second.
> It was in
> http://xml-archive.webweaving.org/xml-archive-xerces-j-dev/0779.html.
>
> > The IBM XML parsers are based on Xerces (on the Java side,
> > they're essentially identical, starting with IBM's version 3,
> > which equates to Xerces-J version 1).
>
> Yes, but he said he had previously used com.ibm.xml.parser.Parser, which
> is only in IBM's version 2. Was that parser also based on Xerces?
>
> -RMS
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
Re: Ampersand Fix.
Posted by Chris Jenkins <cj...@nfld.com>.
>
> DOMParser parser = new DOMParser();
>
>
parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion",
> false);
>
> Which fixes any problems for me. Note that you have to do this _before_
> you make
> any parse() calls on the parser
>
>
This seems to work! This important work-around should perhaps be mentioned
on the parser's download page.
Thanks very much.
-Chris
Re: Ampersand Fix.
Posted by Ryan Schmidt <ry...@cpsc.ucalgary.ca>.
> >Turn off deferred node expansion or whatever it's called and this will
> >go away. It's a problem with how DeferredTextImpl normalizes itself.
>
> I subclassed the Parser and created a function to set and call
> setDeferNodeExpansion(false);
> This didn't change anything either.
Which version of Xerces are you using? I'm using 1.1.1 and the code
to turn off deferral is
DOMParser parser = new DOMParser();
parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion",
false);
Which fixes any problems for me. Note that you have to do this _before_
you make
any parse() calls on the parser
> I replaced the synchronizeData() function from theDeferredTextImpl class
> with the fix's function.
> It seems to be throwing a lot of syntax errors.
I just replaced the contents of that method (from 1.1.1) with the
contents from
my message (cut and paste) and there were no syntax errors. What are the
syntax
errors you are getting?
I'd send you a class file but I'm still not sure this fix is completely
correct.
It does fix your problem. The code I'm not sure about are the two lines
after
the comment //clean up the tree, which might not be compliant with the
DOM spec.
-RMS
Ampersand Fix.
Posted by Chris Jenkins <cj...@nfld.com>.
Hi,
I am not yet sucessful with the fix.
>I believe this is not a "serious flaw", if you read the DOM spec carefully.
>You can use normalize() to get the strings the way I suspect you want them.
I tried to normalize() the root node after parsing, and each node before
calling getNodeValue() on it.
I was not sucessful.
>Turn off deferred node expansion or whatever it's called and this will
>go away. It's a problem with how DeferredTextImpl normalizes itself.
I subclassed the Parser and created a function to set and call
setDeferNodeExpansion(false);
This didn't change anything either.
> It was Andy Clark who suggested I write one. The first one I submitted
> wasn't quite right, and there was no reply (on the list) to the second.
> It was in
> http://xml-archive.webweaving.org/xml-archive-xerces-j-dev/0779.html.
>
I replaced the synchronizeData() function from theDeferredTextImpl class
with the fix's function.
It seems to be throwing a lot of syntax errors.
Could someone please mail the list with a fixed source and class file?
Much thanks,
Chris Jenkins
Re: Ampersand problem.
Posted by Ryan Schmidt <ry...@cpsc.ucalgary.ca>.
Mike Pogue wrote:
>
> OK, sorry...if it was already agreed that this is a bug...
You might be right about the multiple text nodes being part of the DOM
spec (I'm not familiar with it). The bug was in the normalization.
> Do you remember who said they would put in a fix?
It was Andy Clark who suggested I write one. The first one I submitted
wasn't quite right, and there was no reply (on the list) to the second.
It was in
http://xml-archive.webweaving.org/xml-archive-xerces-j-dev/0779.html.
> The IBM XML parsers are based on Xerces (on the Java side,
> they're essentially identical, starting with IBM's version 3,
> which equates to Xerces-J version 1).
Yes, but he said he had previously used com.ibm.xml.parser.Parser, which
is only in IBM's version 2. Was that parser also based on Xerces?
-RMS
Re: Ampersand problem.
Posted by Mike Pogue <mp...@apache.org>.
OK, sorry...if it was already agreed that this is a bug...
Do you remember who said they would put in a fix?
The IBM XML parsers are based on Xerces (on the Java side,
they're essentially identical, starting with IBM's version 3,
which equates to Xerces-J version 1).
Mike
Ryan Schmidt wrote:
>
> Turn off deferred node expansion or whatever it's called and this will
> go away. It's a problem with how DeferredTextImpl normalizes itself.
> I submitted a (possible) fix, someone may be putting it into the CVS
> version, but I'm not sure. (I also think this should be handled in
> the parser, so that only one Text node ends up in DeferredDocumentImpl,
> but I have no idea how to implement that)
>
> Also, I think the previous version of com.ibm.xml.parser.Parser wasn't
> based on Xerces at all, but I could be wrong.
>
> -RMS
>
> Chris Jenkins wrote:
> >
> > Hi,
> >
> > I'm using the org.apache.xerces.parsers.DOMParser to parse a simple xml
> > string that has an internal DTD.
> >
> > It seems that if there is an & in a node, it appears to truncate the
> > tag's data up to the ampersand.
> > So <mytag>blah&moretext</mytag> seems to only contain "blah". I even
> > went so far as to set the feature for the general entities to "true".
> >
> > Someone on the mailing list suggested that the parser creates 3 child nodes,
> > with text:
> > 1. blah
> > 2. &
> > 3.moretext
> >
> > instead of 1 tag with data "blah&moretext". I don't believe this was
> > released with such a very serious flaw, especially when the previous version
> > com.ibm.xml.parser.Parser didn't have this problem.
> >
> > Could you please clarify this issue for me?
> >
> > Much thanks,
> > Chris Jenkins
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> > For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
Re: Ampersand problem.
Posted by Ryan Schmidt <ry...@cpsc.ucalgary.ca>.
Turn off deferred node expansion or whatever it's called and this will
go away. It's a problem with how DeferredTextImpl normalizes itself.
I submitted a (possible) fix, someone may be putting it into the CVS
version, but I'm not sure. (I also think this should be handled in
the parser, so that only one Text node ends up in DeferredDocumentImpl,
but I have no idea how to implement that)
Also, I think the previous version of com.ibm.xml.parser.Parser wasn't
based on Xerces at all, but I could be wrong.
-RMS
Chris Jenkins wrote:
>
> Hi,
>
> I'm using the org.apache.xerces.parsers.DOMParser to parse a simple xml
> string that has an internal DTD.
>
> It seems that if there is an & in a node, it appears to truncate the
> tag's data up to the ampersand.
> So <mytag>blah&moretext</mytag> seems to only contain "blah". I even
> went so far as to set the feature for the general entities to "true".
>
> Someone on the mailing list suggested that the parser creates 3 child nodes,
> with text:
> 1. blah
> 2. &
> 3.moretext
>
> instead of 1 tag with data "blah&moretext". I don't believe this was
> released with such a very serious flaw, especially when the previous version
> com.ibm.xml.parser.Parser didn't have this problem.
>
> Could you please clarify this issue for me?
>
> Much thanks,
> Chris Jenkins
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org