Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Jasper Reports xml formating

Posted on 2007-07-22
3
Medium Priority
?
1,772 Views
Last Modified: 2013-11-18
Hello experts.
I need to format jasper XML report.
I am using
JasperExportManager.exportReportToXmlFile(
                              _printFile, _builtReport + ".xml", false);

to generate the xml report and it produces this type of output:      
                        
 <jasperPrint name="Report" pageWidth="1000" pageHeight="100000" orientation="Landscape">
- <page>
- <text lineSpacingFactor="1.3578125" leadingOffset="-3.1972656" runDirection="LTR" textHeight="0" hyperlinkType="None" hyperlinkTarget="Self" bookmarkLevel="0">
  <reportElement x="238" y="0" width="528" height="23" forecolor="#003399" />
- <textContent>
- <![CDATA[ Referral Report
  ]]>
  </textContent>
  </text>
</page>
 </jasperPrint>

How can I format the report so it has Report as a root element?. I'd like other elements from detail section to be subelements of elements contained in columnHeader, or at least group them somehow and clear all that unnessesary pageWidth and orientation attributes and remove 'page' element...?
Thanks.
0
Comment
Question by:olenadmytrenko
  • 2
3 Comments
 
LVL 17

Expert Comment

by:Dejan Pažin
ID: 19547462

You can always use XSLT to transform the original xml into format you need.

You can use Xalan for that:

http://xml.apache.org/xalan-j/
0
 

Author Comment

by:olenadmytrenko
ID: 19564013
Thanks for that.
To get an associated stylesheet I have to do this:

/ 2a. Get the stylesheet from the XML source.
String media = null , title = null, charset = null;
javax.xml.transform.Source stylesheet = tFactory.getAssociatedStylesheet
                   (new StreamSource("foo.xml"), media, title, charset);

My XML documents doesn't have a stylesheet attached though.. Is it possible to specify an external stylesheet?
Thanks!
0
 
LVL 17

Accepted Solution

by:
Dejan Pažin earned 750 total points
ID: 19564259
Added below are the basic steps taken from http://xml.apache.org/xalan-j/usagepatterns.html. You simply state your source and xsl file.

// 1. Instantiate a TransformerFactory.
javax.xml.transform.TransformerFactory tFactory =
                  javax.xml.transform.TransformerFactory.newInstance();

// 2. Use the TransformerFactory to process the stylesheet Source and
//    generate a Transformer.
javax.xml.transform.Transformer transformer = tFactory.newTransformer
                (new javax.xml.transform.stream.StreamSource("foo.xsl"));

// 3. Use the Transformer to transform an XML Source and send the
//    output to a Result object.
transformer.transform
    (new javax.xml.transform.stream.StreamSource("foo.xml"),
     new javax.xml.transform.stream.StreamResult( new
                                  java.io.FileOutputStream("foo.out")));


Or, you can also use commandline tool:

http://xml.apache.org/xalan-j/commandline.html
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question