Project

Profile

Help

Use Saxon as a serializer and output escaping

Added by Anonymous over 16 years ago

Legacy ID: #4572353 Legacy Poster: Andrew Fang (afang4)

Trying to use Saxon (8.9) as serializer. To make it implementation independent, it is constructed via JAXP, i.e. TransformerHandler handler = sax.newTransformerHandler(); handler.getTransformer().setOutputProperties(props); Result result = new StreamResult(stream); handler.setResult(result); The handler can then be used as a ContentHandler in a pipeline like environment to allow additional processing between transformation and serialization. The implementation works fine except that I cannot seem to make output escaping work. For a text output like <xsl:text disable-output-escaping="yes">&lt;text&gt;</xsl:text>, the transformer (Saxon as well) sends out events: [PI event]: <?javax.xml.transform.disable-output-escaping?> [character event]: <text> [PI event]: <?javax.xml.transform.enable-output-escaping?> It would be ideal if the serializer can honor the disable/enable output escaping PIs. I find that with minor changes in net.sf.saxon.event.RecevingContentHandler.java, we can make it behave the way we want. Is there a chance that this can go into next saxon release? Thanks a lot for your help.


Replies (8)

Please register to reply

RE: Use Saxon as a serializer and output esca - Added by Anonymous over 16 years ago

Legacy ID: #4572383 Legacy Poster: Michael Kay (mhkay)

No, I'm not prepared to make changes to ReceivingContentHandler to achieve this: it's not an important enough requirement to justify changes to this critical class. (And it's the kind of functionality that one really regrets adding four releases downstream when the design has changed.) I suggest you subclass RCH to achieve the required behaviour, and create a SAXTransformerFactory that generates a serializer containing your subclass.

RE: Use Saxon as a serializer and output escaping - Added by Anonymous over 16 years ago

Legacy ID: #4572448 Legacy Poster: Andrew Fang (afang4)

Unfortunately there is no easy way to subclass RCH as the change involve a private method "flush()". The proposed changes involve recognizing the escaping PI and set flag accordingly in flush() method. It looks like we have to either maintain our own change or fall back to xalan's implementation, which does honor the escaping PIs. Thanks for your help.

RE: Use Saxon as a serializer and output escaping - Added by Anonymous over 16 years ago

Legacy ID: #4582145 Legacy Poster: Paul Grosso (pgrosso)

It would be really nice to be able to upgrade from saxon 6.5 to 8.9, but we can't do that if disable-output-escaping stops working. And as Andrew explained above, we cannot solve the problem by subclassing RCH. Mike, at http://osdir.com/ml/text.xml.saxon.help/2005-05/msg00100.html you pointed out to a user that their problem was that they "switched from a ContentHandler that understands and implements disable-output-escaping to one that doesn't." It seems that's what happens when switching from saxon 6.5 to 8.9. This seems to be the last issue with our switching from 6.5 to 8.9. Is there any chance you would reconsider adding support for the d-o-e PIs to maintain compatibility between 6.5 and 8.9? paul

RE: Use Saxon as a serializer and output esca - Added by Anonymous over 16 years ago

Legacy ID: #4582826 Legacy Poster: Michael Kay (mhkay)

OK, I've implemented it. It won't be on by default; you will have to do TransformerFactoryImpl tf = new TransformerFactoryImpl(); tf.setAttribute(FeatureKeys.USE_PI_DISABLE_OUTPUT_ESCAPING, Boolean.TRUE); This means that applications that might currently be writing these PIs to a DOM (or to a Saxon tree) will continue to do so. Michael Kay http://www.saxonica.com/

RE: Use Saxon as a serializer and output escaping - Added by Anonymous over 16 years ago

Legacy ID: #4584717 Legacy Poster: Andrew Fang (afang4)

Thanks a lot!!

RE: Use Saxon as a serializer and output escaping - Added by Anonymous over 16 years ago

Legacy ID: #4606547 Legacy Poster: Andrew Fang (afang4)

Michael, I downloaded 9.0, but the disable output escaping PI does not seem to work. I did set the FeatureKeys.USE_PI_DISABLE_OUTPUT_ESCAPING attribute. It seems to me that in the following code in RCH, the escapingDisabled value should be set prior to calling flush(). if (allowDisableOutputEscaping) { if (name.equals(Result.PI_DISABLE_OUTPUT_ESCAPING)) { flush(); escapingDisabled = true; return; } else if (name.equals(Result.PI_ENABLE_OUTPUT_ESCAPING)) { flush(); escapingDisabled = false; return; } }

RE: Use Saxon as a serializer and output esca - Added by Anonymous over 16 years ago

Legacy ID: #4606803 Legacy Poster: Michael Kay (mhkay)

Well, the code passed my tests, and the logic looks right to me. Actually looking at it again the calls on flush() are redundant, because that's the first thing the processingInstruction() method does - and it clearly makes sense to flush the pending text before you set the switch, because you don't want to disable escaping for the text that was put into the buffer before the PI came along. My only slight reservation about the logic is that flush() is setting the WHOLE_TEXT_NODE flag, which is telling the recipient that they aren't going to receive adjacent text nodes, which isn't actually the case if one of these PIs comes along. But WHOLE_TEXT_NODE only matters if you are building a TinyTree, which you presumably are not. How are you running it, in particular what have you got downstream on the pipeline? Michael Kay http://www.saxonica.com/

RE: Use Saxon as a serializer and output escaping - Added by Anonymous over 16 years ago

Legacy ID: #4608998 Legacy Poster: Andrew Fang (afang4)

Thanks for looking into it. It works for me now, I was setting the attribute to a wrong transformer factory. There are two transformer factory in our pipeline, one for transformation one for serialization. Andrew

    (1-8/8)

    Please register to reply