processing html tags inside xml with fop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jamieg99
    New Member
    • Dec 2007
    • 3

    #1

    processing html tags inside xml with fop

    Hello,

    I've got an object that's being converted into SAXSource and then converted into a pdf with FOP. Some of the data however is in HTML format inside the xml tags and is being escaped (>, etc) before it transformed.

    I'd like to have this these html tags parsed as actual elements by the stylesheet, which would mean reading it in it's unescaped format, but I can't figure out how to do this. I have "disable-output-escaping" set in the stylesheet, but I think the data in the xml has already been parsed as "escaped" before it gets to the stylesheet and processed.

    Here's the code for converting.


    FOUserAgent foUserAgent = getUserAgent();

    PDFRenderer pdfrenderer = new PDFRenderer();
    pdfrenderer.set UserAgent(foUse rAgent);
    foUserAgent.set RendererOverrid e(pdfrenderer);

    URIResolver resolver = myWebContext.ge tResolver();
    foUserAgent.set URIResolver(res olver);

    ByteArrayOutput Stream out = new ByteArrayOutput Stream();

    byte[] b = null;
    try {

    TransformerFact ory factory = TransformerFact ory.newInstance ();


    Transformer transformer = factory.newTran sformer();

    //transformer.set OutputProperty( "disable-output-escaping", "yes");
    // kicks back error --- invalid property


    Fop fop = fopFactory.newF op(MimeConstant s.MIME_PDF, foUserAgent, out);

    Source xsl = resolver.resolv e(xslFilename, null);

    transformer = factory.newTran sformer(xsl);

    res = new SAXResult(fop.g etDefaultHandle r());

    transformer.tra nsform(xmlSrc, res);

    b = out.toByteArray ();


    Any help would be greatly appreciated.

    Thanks!

    -Jamie
  • jamieg99
    New Member
    • Dec 2007
    • 3

    #2
    After much futzing around with this, I ended up using JAXB to generate the xml I needed and enclosing the HTML data inside CDATA sections.

    I then changed TransformerFact oryImpl to use saxon and process the stylesheet:

    System.setPrope rty("javax.xml. transform.Trans formerFactory", "net.sf.saxon.T ransformerFacto ryImpl");

    And used saxon's saxon:parse() function to further process the html-tag data inside the CDATA section since it's well-formed html. That gave me an xml result for fop to handle which included the html I needed to create the correct pdf formatting.

    It now works, although probably not the greatest of solutions.

    I couldn't figure out how to generate CDATA sections with SAX and LexicalHandlers , so this was the next best alternative.

    Cheers


    -Jamie

    Comment

    Working...