Jump to content
We've recently updated our Privacy Statement, available here ×

Problem with xpath


gabri124

Recommended Posts

Hello I am new using jasper library and i wanna to run and easily example.

 

I have made the jrmxl and I have a xml file with the data.

 

But when i made the pdf report the pdf is not filled with the values of xml.

 

Can u help me?

 

 

Code:
  public static void main(String[] args)    {         String filexml = args[0];     	byte[] PDFSalida = null;		     	ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();           try          {           System.out.println("Create DataSource...");           File file =  new File(filexml);           System.out.println("EL FICHERO ES  "+file.getAbsolutePath());           JRXmlDataSource xmlDataSource = new JRXmlDataSource(file,"/personas/persona");           System.out.println("Compiling report...");                       Map<String, Object> parameters = new HashMap<String, Object>();           JasperCompileManager.           compileReportToFile("c:/Temp/jrmx/personas.jrxml");            System.out.println("Filled report...");            byte[] bytes = JasperRunManager.            runReportToPdf("c:/Temp/jrmx/personas.jasper",parameters,xmlDataSource);            String filePDF = filexml.substring(0,filexml.length()-3)+".pdf";            FileOutputStream output = new FileOutputStream(filePDF);                                        		                 output.write(bytes);            output.flush();            output.close();             System.out.println("Done!");          }          catch (JRException e)          {            e.printStackTrace();          } catch (FileNotFoundException e) {            // TODO Auto-generated catch block            e.printStackTrace();        } catch (IOException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }    }
Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Hi gabri,

Your problem is in the jrxml file with the definition of the fields. You have created three fields but no description is defined for them so the report does not know where to get the values from. and it shows null. I made the following modification in the definition of the fields:

 <field name="nombre" class="java.lang.String">
    <fieldDescription><![CDATA[nombre]]></fieldDescription>
  </field>
  <field name="edad" class="java.lang.String">
    <fieldDescription><![CDATA[edad]]></fieldDescription>
  </field>
  <field name="domicilio" class="java.lang.String">
    <fieldDescription><![CDATA[domicilio]]></fieldDescription>
  </field>

I have tried it with your source code and it works ok. I attach the corrected jrxml file.

Hope this helps

Regards.
 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...