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

Null value when using XML Data Source


2004 IR Help

Recommended Posts

By: cyunntan - cyunntan

Null value when using XML Data Source

2005-10-31 02:35

Hi All,

 

Im using XMLDataSource datasource connection to generate my report. I've got the below XML

 

<A>

<Payment>

<BrchCde>

<RcptNo>

</Payment>

<Payment>

<BrchCde>

<RcptNo>

</Payment>

</A>

 

FieldName: BrchCde

Field class type : java.lamg.String

Field Name: RcptNo

Field class type : java.lamg.String

 

Select expression : /A/Payment

 

But ..im getting null value for the two columns when i execute the report to generate PDF..

Anyone could provide me with an explaination ? Im stuck ..

Thank you..

 

regards,

cyunn

 

 

 

 

 

 

By: Vincenzo Amoruso - vinciamo

RE: Null value when using XML Data Source

2005-10-31 04:40

I think that the Xml file should be :

<A>

<Payment>

<BrchCde>aaaaaaa</BrchCde>

<RcptNo>aaaaaaaa</RcptNo>

</Payment>

<Payment>

<BrchCde>bbbbb</BrchCde>

<RcptNo>bbbbbbbbbb</RcptNo>

</Payment>

</A>

 

query :

/A/Payment

 

Is you are using IReport take a look in samplesdatasource sub directory

 

Regards

Vincenzo

 

 

 

 

By: cyunntan - cyunntan

RE: Null value when using XML Data Source

2005-10-31 07:16

Hi Vincenzo,

 

Yea.It's my mistake when posting the question. Actually, i've got the XML source correctly .It's just that i don't seem to get the value of BrchCde and RcptNo from my XML source. It only shows null , null on my PDF..

Im trying Jasper by refering to the XMLDataSource Sample ..

 

Any idea what have gone wrong ? It looks simple..but im having quite a hard time here ..

Hope to hear from you all soon..

Thank you

 

Regards,

cyunn

 

 

 

 

By: Vincenzo Amoruso - vinciamo

RE: Null value when using XML Data Source

2005-10-31 07:53

Hi cyunn!

 

Only one question, are you tryng to create a report with the two details, first for item rows and second for payment rows, both in the same jrxml?

 

is it true?

 

In this case is better to create a subreport for payment rows.

 

 

Regards

Vincenzo!

 

 

 

 

 

By: Lucian Chirita - lucianc

RE: Null value when using XML Data Source

2005-10-31 08:25

JRXmlDataSource uses field descriptions as relative XPaths. Did you set the field descriptions?

 

HTH,

Lucian

 

 

 

 

By: cyunntan - cyunntan

RE: Null value when using XML Data Source

2005-10-31 18:20

Hi Lucian,

 

Yea. I've set the field name exactly as the field description.

 

FieldName : BrchCde

FieldDescriptioin : BrchCde

FieldName : RcptNo

FieldDescription : RcptNo

Both are java.langs.String type.

 

Anything loopholes that i might have miss out ?

Thank you Lucian for your response. :)

 

Hi Vincenzo,

Im planning to display the list of payment. It is straightforward. As my example XML says, I wish to display two records of payment made , where each records will have 2 attributes i.e BrchCde and RcptNo

 

Eg:

List of Payment :

BrchCde 1 RcptNo 001

BrchCde 2 RcptNo 002

 

Something simple. Coz' im in the stage of trying out . If I can't solve this, meaning i can't proceed :(

 

Im new to JP.So, i don't know if i have miss out any steps while creating a report. Thus, i shall briefly explain what i have done.

 

1.Get 1 sample of simple XML datasource

2.Design 2 Fields. Set the text field for each with

the value $F{BrchCde} and $F{RcptNo}

3.Set the parameter field for each text field under

Field Tab.One is BrchCde and another is

RcptNo. Same value for fieldName and

fieldDescription.

4.Set the XML file datasouce to point to my

XML.

Name : Payment

XML File : C:/Test.xml

Select expression : /A/Payment/

5.Compile and execute my report in PDF format.

 

Then i got null for BrchCde and null for RcptNo as the result ..

Anything that i've miss out ? By the way, what is to be filled in for the Name section in my Step4? Is it my XML name? Test? Or the highest node in my XML source or simply anything?

 

Thank you Vincenzo for your response too. :)

 

Please advise me...Looking forward to hear from SourceForge fellows..:)

 

Regards,

cyunn

 

 

 

 

 

 

By: Lucian Chirita - lucianc

RE: Null value when using XML Data Source

2005-11-01 00:01

Could you post your report jrxml and the input xml? If we see the whole thing, we should spot the problem..

 

Regards,

Lucian

 

 

 

 

By: cyunntan - cyunntan

RE: Null value when using XML Data Source

2005-11-01 02:05

Hi Lucian,

 

Ok. I'll post them.

This is my payment.jrxml

 

<?xml version="1.0" encoding="UTF-8" ?>

<!-- Created with iReport - A designer for JasperReports -->

<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

<jasperReport

name="payment"

columnCount="1"

printOrder="Vertical"

orientation="Portrait"

pageWidth="595"

pageHeight="842"

columnWidth="535"

columnSpacing="0"

leftMargin="30"

rightMargin="30"

topMargin="20"

bottomMargin="20"

whenNoDataType="NoPages"

isTitleNewPage="false"

isSummaryNewPage="false">

<property name="ireport.scriptlethandling" value="2" />

<import value="java.util.*" />

<import value="net.sf.jasperreports.engine.*" />

<import value="net.sf.jasperreports.engine.data.*" />

<field name="BrchCde" class="java.lang.String">

<fieldDescription><![CDATA[brchCde]]></fieldDescription>

</field>

<field name="RcptNo" class="java.lang.String">

<fieldDescription><![CDATA[RcptNo]]></fieldDescription>

</field>

<background>

<band height="0" isSplitAllowed="true" >

</band>

</background>

<title>

<band height="50" isSplitAllowed="true" >

<staticText>

<reportElement

mode="Opaque"

x="6"

y="2"

width="527"

height="43"

forecolor="#000000"

backcolor="#FFCC33"

key="staticText-1"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false"/>

<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>

<textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" lineSpacing="Single">

<font fontName="Arial" pdfFontName="Helvetica" size="14" isBold="true" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" />

</textElement>

<text><![CDATA[Payment Report]]></text>

</staticText>

</band>

</title>

<pageHeader>

<band height="50" isSplitAllowed="true" >

</band>

</pageHeader>

<columnHeader>

<band height="30" isSplitAllowed="true" >

<staticText>

<reportElement

mode="Opaque"

x="21"

y="4"

width="78"

height="22"

forecolor="#000000"

backcolor="#CC9900"

key="staticText-2"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false"/>

<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>

<textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" lineSpacing="Single">

<font fontName="Arial" pdfFontName="Helvetica" size="12" isBold="true" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" />

</textElement>

<text><![CDATA[branch Code]]></text>

</staticText>

<staticText>

<reportElement

mode="Opaque"

x="120"

y="5"

width="78"

height="23"

forecolor="#000000"

backcolor="#CC9900"

key="staticText-3"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false"/>

<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>

<textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" lineSpacing="Single">

<font fontName="Arial" pdfFontName="Helvetica" size="12" isBold="true" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" />

</textElement>

<text><![CDATA[Receipt No]]></text>

</staticText>

</band>

</columnHeader>

<detail>

<band height="100" isSplitAllowed="true" >

<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >

<reportElement

mode="Opaque"

x="19"

y="8"

width="80"

height="22"

forecolor="#000000"

backcolor="#FFFFFF"

key="textField-1"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false"/>

<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>

<textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single">

<font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" />

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[$F{BrchCde}]]></textFieldExpression>

</textField>

<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >

<reportElement

mode="Opaque"

x="122"

y="10"

width="100"

height="19"

forecolor="#000000"

backcolor="#FFFFFF"

key="textField-2"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false"/>

<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>

<textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single">

<font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" />

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[$F{RcptNo}]]></textFieldExpression>

</textField>

</band>

</detail>

<columnFooter>

<band height="30" isSplitAllowed="true" >

</band>

</columnFooter>

<pageFooter>

<band height="50" isSplitAllowed="true" >

</band>

</pageFooter>

<lastPageFooter>

<band height="50" isSplitAllowed="true" >

</band>

</lastPageFooter>

<summary>

<band height="50" isSplitAllowed="true" >

</band>

</summary>

</jasperReport>

 

 

************************

 

While this is my input XML: Text2.xml

 

<?xml version="1.0" encoding="UTF-8"?>

<NODE1>

<NODE2>

<BrchCde type="string" length="2">HQ</BrchCde>

<RcptNo type="string" length="7">0000010</ReceiptNo>

</NODE2>

<NODE2>

<BrchCde type="string" length="2">AP</BrchCde>

<RcptNo type="string" length="7">0000011</ReceiptNo>

</NODE2>

</NODE1>

 

 

Please advice me ...Thank you so much..

 

Regards,

cyunn

 

 

 

 

By: cyunntan - cyunntan

RE: Null value when using XML Data Source

2005-11-01 02:14

Sorry ..there is some mistake for my input XML..

 

This should be the one ..

 

<?xml version="1.0" encoding="UTF-8"?>

<NODE1>

<NODE2>

<BrchCde type="string" length="2">HQ</BrchCde>

<RcptNo type="string" length="7">0000010</RcptNo>

</NODE2>

<NODE2>

<BrchCde type="string" length="2">AP</BrchCde>

<RcptNo type="string" length="7">0000011</RcptNo>

</NODE2>

</NODE1>

 

 

Thank You

 

Regards,

cyunn

 

 

 

 

By: Lucian Chirita - lucianc

RE: Null value when using XML Data Source

2005-11-01 02:35

Weird, it works fine for me using new JRXmlDataSource("c:\tmp\xml.xml", "/NODE1/NODE2")

 

What JR version are you using?

 

 

 

 

By: cyunntan - cyunntan

RE: Null value when using XML Data Source

2005-11-01 17:33

Hi Lucian,

 

Im using JP version 0.4.1.

Still im getting null values.

 

Im using the java class provided in the XMLDataSource sample to compile my jrxml and modify the parameter accordingly to fit my input XML.

 

JRXmlDataSource(new BufferedInputStream(new FileInputStream("Text2.xml")), "/Node1/Node2"));

 

Any idea ? Thank You for your advice ..

 

Regards,

cyunn

 

 

 

 

 

By: Lucian Chirita - lucianc

RE: Null value when using XML Data Source

2005-11-02 00:03

XPath is case sensitive, you need /NODE1/NODE2.

 

HTH,

Lucian

 

 

 

 

By: cyunntan - cyunntan

RE: Null value when using XML Data Source

2005-11-11 00:00

Hi Lucian,

 

I've been trying out on your advice this past few days. Take note on the case sensitive part as well. Still im getting null values. Anyway,i'll try to redesign my report once again, maybe i just overlook something. Or you've any solutions ?

 

By the way, when i try to launch ireport 0.4.1 at other PC with j2sdk1.4.2_05 , i was unable to launch it.

Im getting this kind of error message :

 

Exception in thread "main" java.lang.UnsupportedClassVersionError: it/businesslo

gic/ireport/gui/MainFrame (Unsupported major.minor version 48.0)

at java.lang.ClassLoader.defineClass0(Native Method)

at java.lang.ClassLoader.defineClass(Unknown Source)

 

Any idea ?

 

Thank you for your advice .

 

Regards,

cyunn

 

 

 

 

 

By: Lucian Chirita - lucianc

RE: Null value when using XML Data Source

2005-11-17 03:44

Hi

 

I'm out of ideas. The files you posted worked for me.

 

You could get the Jasper sources and debug it to see what goes wrong.

 

Regarding the iReport issue, try posting on the iReport forum/mailing list.

 

Regards,

Lucian

 

 

 

 

By: nishant - nkaushik

RE: Null value when using XML Data Source

2006-03-28 06:43

Hi!

 

Did you ever solve this problem??? i am facing a similar problem... mentioned below... ur help will be appretiated

 

Did you ever solve this problem?

 

I am trying to access the xml file and display the details in a pdf,i keep getting this error

 

Caused by: java.lang.LinkageError: Class org/w3c/dom/traversal/NodeIterator violates loader constraints: definition mismatch between parent and child loaders

 

if i have the description tag for the field....if i remove the description tag then the pdf is generated but i get all null values inside the report.........

 

this is the code i use to parse and compile the file

 

else if(request.getParameter("GetFromXMLSourceFormSubmit") != null){

 

Map params = new HashMap();

try

{

System.out.println("111111111");

//Document document = JRXmlUtils.parse(new File("C:/WINDOWS/Profiles/nkaushik/IBM/rationalsdp6.0/workspace/Source/JasperReportsSampleWar/WebContent/WEB-INF/classes/northwind.xml"));

JRXmlDataSource xmlDataSource= new JRXmlDataSource(new File("C:/WINDOWS/Profiles/nkaushik/IBM/rationalsdp6.0/workspace/Source/JasperReportsSampleWar/WebContent/WEB-INF/classes/northwind.xml"),"/Northwind/Customers");

//JRXmlDataSource xmlDataSource= new JRXmlDataSource(document,"/Northwind/Customers");

JasperReport jasperReport = JasperCompileManager.compileReport("C:/WINDOWS/Profiles/nkaushik/IBM/rationalsdp6.0/workspace/Source/JasperReportsSampleWar/WebContent/WEB-INF/classes/Customers.jrxml");

//Document document = JRXmlUtils.parse(new File("C:/WINDOWS/Profiles/nkaushik/IBM/rationalsdp6.0/workspace/Source/JasperReportsSampleWar/WebContent/WEB-INF/classes/northwind.xml"));

 

System.out.println("22222222222222");

//params.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, document);

System.out.println("333333333333333");

//JasperRunManager.runReportToPdfFile("C:/WINDOWS/Profiles/nkaushik/IBM/rationalsdp6.0/workspace/Source/JasperReportsSampleWar/WebContent/WEB-INF/classes/Customers.jrxml", params);

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params,xmlDataSource);

System.out.println("444444444444444");

JasperExportManager.exportReportToPdfFile(jasperPrint,"c:/reportFromXML.pdf");

System.out.println("5555555555555555");

JasperExportManager.exportReportToHtmlFile(jasperPrint,"c:/reportFromXML.html");

System.out.println("66666666666666666666");

}

catch (JRException e)

 

i cant get pass beyond the message333333333... if description tag is there

 

plz advice

 

Nishant

 

 

 

 

By: Nicky15 - nicky15

RE: Null value when using XML Data Source

2006-06-01 15:54

Have you populated your HashMap variable 'params'?

Please let me know how you have done it. I get error on the JRXmlUtils line.

 

Thanks.

Link to comment
Share on other sites

  • 1 year later...
  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

  • 2 weeks later...
  • 3 months later...

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...