You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Andreas Hartmann <an...@apache.org> on 2009/03/04 17:52:22 UTC
Re: IncludeXMLConsumer with RedundantNamespacesFilter does not
output comments
Thorsten Scherler schrieb:
> On Fri, 2009-02-27 at 14:26 +0100, Andreas Hartmann wrote:
>> StringXMLizable.toSAX() sets only the content handler of the SAX
>> parser.
>>
>> Maybe it makes sense to set the lexical handler, if possible?
>>
>> public void toSAX(ContentHandler contentHandler) throws
>> SAXException {
>> final SAXParser parser = getContext().parser;
>> parser.getXMLReader().setContentHandler(contentHandler);
>>
>> + if (contentHandler instanceof LexicalHandler) {
>> + parser.getXMLReader().setProperty(
>> + "http://xml.org/sax/properties/lexical-handler",
>> + (LexicalHandler) contentHandler);
>> + }
>>
>> InputSource is = new InputSource(new StringReader(data));
>> try {
>> parser.getXMLReader().parse(is);
>> } catch (IOException e) {
>> throw new SAXException(e);
>> }
>> }
>
> I agree that this change is the elegant solution for the problem. Can
> you apply it, if nobody objects.
Up to now, nobody has objected – but I have to admit I don't like the
automagic approach that much. Maybe we'd rather add a method like
StringXMLizable.toSAX(XMLConsumer consumer)
to make it more obvious that the LexicalHandler events are emitted?
-- Andreas
--
Andreas Hartmann, CTO
BeCompany GmbH
http://www.becompany.ch
Tel.: +41 (0) 43 818 57 01
Re: IncludeXMLConsumer with RedundantNamespacesFilter does not
output comments
Posted by Thorsten Scherler <th...@juntadeandalucia.es>.
On Wed, 2009-03-04 at 17:52 +0100, Andreas Hartmann wrote:
> Thorsten Scherler schrieb:
> > On Fri, 2009-02-27 at 14:26 +0100, Andreas Hartmann wrote:
> >> StringXMLizable.toSAX() sets only the content handler of the SAX
> >> parser.
> >>
> >> Maybe it makes sense to set the lexical handler, if possible?
> >>
> >> public void toSAX(ContentHandler contentHandler) throws
> >> SAXException {
> >> final SAXParser parser = getContext().parser;
> >> parser.getXMLReader().setContentHandler(contentHandler);
> >>
> >> + if (contentHandler instanceof LexicalHandler) {
> >> + parser.getXMLReader().setProperty(
> >> + "http://xml.org/sax/properties/lexical-handler",
> >> + (LexicalHandler) contentHandler);
> >> + }
> >>
> >> InputSource is = new InputSource(new StringReader(data));
> >> try {
> >> parser.getXMLReader().parse(is);
> >> } catch (IOException e) {
> >> throw new SAXException(e);
> >> }
> >> }
> >
> > I agree that this change is the elegant solution for the problem. Can
> > you apply it, if nobody objects.
>
> Up to now, nobody has objected – but I have to admit I don't like the
> automagic approach that much. Maybe we'd rather add a method like
>
> StringXMLizable.toSAX(XMLConsumer consumer)
>
> to make it more obvious that the LexicalHandler events are emitted?
Personally I like the automatic one, since if I pass an instanceof
LexicalHandler then I expect that the events are invoked.
salu2
--
Thorsten Scherler <thorsten.at.apache.org>
Open Source Java <consulting, training and solutions>
Sociedad Andaluza para el Desarrollo de la Sociedad
de la Información, S.A.U. (SADESI)