Jump to content
Changes to the Jaspersoft community edition download ×

Urgent help in Querying XML DataSource


nitin403

Recommended Posts

Hi!

I creating an report using XML files as datasource.

I have tried using multiple combination of querying the datasource in iReport.

But none were able give the correct result.

Whenever I query the datasource it give either null or only the first value of the result.

 

My XML datasource is

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

<EvalData>
<Quarter>
<no>Q3'06</no>
<EvalValue>3</EvalValue>
<CommonValue>Text1</CommonValue>
</Quarter>

<Quarter>
<no>Q4'06</no>
<EvalValue>1</EvalValue>
<CommonValue>Text1</CommonValue>
</Quarter>

<Quarter>
<no>Q1'07</no>
<EvalValue>4</EvalValue>
<CommonValue>Text</CommonValue>
</Quarter>
</EvalData>

<QHighLight>

<Header hdrText="Created IC Calculates and rolled out to field">
<subHeader>We are posting personalized IC Calculators every month.</subHeader>
</Header>


<Header hdrTest="Cteated SA(Sales Analysis) Reports and rolled out to field managers">
<subHeader>We are posting SA Reports every month.</subHeader>
</Header>


<Header hdrTest="Created Personalized web homepages with all current and revelant IC documents">
<subHeader>Created personalized Viewer homepages where the reps get links.</subHeader>
</Header>


<Header hrdtest="Reduced the proceeeing time for monthly processing">
<subHeader>Completing the non-payout month processing in just one week.</subHeader>
</Header>


</QHighLight>

<OutlookNQ>
<Header>1-Create new IC Calculator Summary report and deliver the same in non payout month</Header>

<Header>2-Deliver Budget Management and Plan Effectiveness Reports concurrent with the Payroll report.</Header>

</OutlookNQ>

<SynygyCI>

<Name>Schering-Plough</Name>
<Title>Healthcare Products</Title>
<Phone_Number>610-494-3300x2129</Phone_Number>
<Email_Add>proj129@synygy.com</Email_Add>

<Name>Divid Grossberg</Name>
<Title>Managing Consultant</Title>
<Phone_Number>610-494-3300x(7045)</Phone_Number>
<Email_Add>grossberg@synygy.com</Email_Add>

<Name>Peter Lamb</Name>
<Title>Managing Direntor</Title>
<Phone_Number>610-494-3300x(7656)</Phone_Number>
<Email_Add>lamb@synygy.com</Email_Add>

</SynygyCI>

<ccur>
<quarter no="1">
<Credit>210 </Credit>
<TC>180</TC>
</quarter>
<quarter no="2">
<Credit>190 </Credit>
<TC>160</TC>
</quarter>
<quarter no="3">
<Credit>175 </Credit>
<TC>155</TC>
</quarter>
</ccur>

</MyReport>

My JRXML files is

Code:
[code]<?xml version="1.0" encoding="ISO-8859-1" ?>
<!-- Created with iReport - A designer for JasperReports -->
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport
name="OutlokkNQ"
columnCount="1"
printOrder="Vertical"
orientation="Portrait"
pageWidth="535"
pageHeight="842"
columnWidth="535"
columnSpacing="0"
leftMargin="0"
rightMargin="0"
topMargin="0"
bottomMargin="0"
whenNoDataType="AllSectionsNoDetail"
isTitleNewPage="false"
isSummaryNewPage="true"
whenResourceMissingType="Error">
<property name="ireport.scriptlethandling" value="0" />
<property name="ireport.encoding" value="ISO-8859-1" />
<import value="java.util.*" />
<import value="net.sf.jasperreports.engine.*" />
<import value="net.sf.jasperreports.engine.data.*" />

<queryString language="xPath"><![CDATA[/MyReport/OutlookNQ]]></queryString>

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

<background>
<band height="0" isSplitAllowed="true" >
</band>
</background>
<title>
<band height="33" isSplitAllowed="true" >
<staticText>
<reportElement
mode="Opaque"
x="0"
y="0"
width="266"
height="28"
backcolor="#CCCCCC"
key="staticText"/>
<box topBorder="Thin" topBorderColor="#000000" leftBorder="Thin" leftBorderColor="#000000" rightBorder="Thin" rightBorderColor="#000000" bottomBorder="Thin" bottomBorderColor="#000000"/>
<textElement textAlignment="Left" verticalAlignment="Bottom" rotation="None" isStyledText="true" lineSpacing="Single">
<font fontName="Arial" size="18" isBold="true"/>
</textElement>
<text><![CDATA[Outlook for Next Quarter]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="80" isSplitAllowed="true" >
</band>
</pageHeader>
<columnHeader>
<band height="0" isSplitAllowed="true" >
</band>
</columnHeader>
<detail>
<band height="44" isSplitAllowed="true" >
<elementGroup><!-- Start: 1 !-->
<textField isStretchWithOverflow="true" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="17"
y="7"
width="389"
height="30"
key="textField-1"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement isStyledText="true">
<font fontName="Times New Roman" size="10" isBold="true"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{Header}]]></textFieldExpression>
</textField>
<image evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="6"
y="7"
width="11"
height="10"
key="image-1"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<graphicElement stretchType="NoStretch"/>
<imageExpression class="java.lang.String"><![CDATA["C:\Documents and Settings\Jainn\My Documents\My Pictures\bullet.bmp"]]></imageExpression>
</image>
</elementGroup><!-- End 1 !-->
</band>
</detail>
<columnFooter>
<band height="0" isSplitAllowed="true" >
</band>
</columnFooter>
<pageFooter>
<band height="90" isSplitAllowed="true" >
</band>
</pageFooter>
<summary>
<band height="0" isSplitAllowed="true" >
</band>
</summary>
</jasperReport>

 

Please help I have wasted days for this one but didn't got any fruitful result.

 

Later on I am also going to query the complete data source.

I have read many tutorials on Xpath also.

 

Thank for your help in advance.

Post edited by: nitin403, at: 2007/08/01 08:35

Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Three things that helped me out on this problem,

 

1) http://w3schools.com/xpath/default.asp

 

That has everything you need (or don't need) for XPath.

 

2) XMLDataSource examples in the demo folder of the distribution

 

3) This was the big one, in iReport, you can specify a data source and an XPath query. I knew that once the template file got saved, it lost the data source (it assumes you will be giving it a proper data source later). The .jrxml file has a reference to the XPath inside it when it is saved, but when you create the XMLDataSource object without an XPath argument, it doesn't seem to default to the template's query. The only work around that I have found is to specify the correct XPath query with the XML input. It would seem this would not be the best way to do this, so if anyone else has a better solution, please help us out. I would like for the specified query from the report template be used, instead of having to specify one in the data source.

 

Code:

//TODO Figure a way around forcing the select statement.
//This will make the generic class much more robust.
JRXmlDataSource source = new JRXmlDataSource(xmlInStream,"/Report/Record"«»);
Link to comment
Share on other sites

jwsmith22 wrote:

I would like for the specified query from the report template be used, instead of having to specify one in the data source.

 

When you use a data source to fill a report, it will override/ignore the report query.

 

If you want to use the report query, you should not pass a data source but pass only values for the parameters required by the query executer. For the XPath query executer, you need to pass an XML document (you can also see this in the xmldatasource JR sample):

Code:

Document document = ..load document..;
params.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, document);
JasperPrint print = JasperFillManager.fillReport(jasperReport, params);

 

HTH,

Lucian

Link to comment
Share on other sites

Hi lucianc and jwsmith22!

Thank a lot lucianc and jwsmith22.

 

Below is my XML datasource.

In my report let say I need /MyReport/EvalData/Quarter/no and /MyReport/QHighLight/HeaderQH/subHeader feild to be used in my Report.

 

I tried using pipe function but it fails to retrieve all the field,it gave me only first field.

So my situation what should I do.

 

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

<EvalData>
<Quarter>
<no>Q306</no>
<EvalValue>3</EvalValue>
<CommonValue>Text1</CommonValue>
</Quarter>

<Quarter>
<no>Q406</no>
<EvalValue>1</EvalValue>
<CommonValue>Text1</CommonValue>
</Quarter>

<Quarter>
<no>Q107</no>
<EvalValue>4</EvalValue>
<CommonValue>Text</CommonValue>
</Quarter>
</EvalData>

<QHighLight>

<HeaderQH hdrText="Created IC Calculates and rolled out to field">
<subHeader>We are posting personalized IC Calculators every month</subHeader>
<subHeader>Weghfgh are posting personalized IC Calculators every month</subHeader>
</HeaderQH>


<HeaderQH hdrText="Created SA(Sales Analysis) Reports and rolled out to field managers">
<subHeader>We are posting SA Reports every month</subHeader>
</HeaderQH>


<HeaderQH hdrText="Created Personalized web homepages with all current and revelant IC documents">
<subHeader>Created personalized Viewer homepages where the reps get links</subHeader>
</HeaderQH>


<HeaderQH hdrText="Reduced the proceeeing time for monthly processing">
<subHeader>Completing the non-payout month processing in just one week</subHeader>
</HeaderQH>


</QHighLight>

<OutlookNQ>

<Header1>1Create new IC Calculator Summary report and deliver the same in non payout month</Header1>
<Header1>2Deliver Budget Management and Plan Effectiveness Reports cocurrent with the Payroll report.</Header1>

</OutlookNQ>

<SynygyCI>
<Employee>
<Name>Schering-Plough</Name>
<Title>Healthcare Products</Title>
<Phone_Number>610-494-3300x2129</Phone_Number>
<Email_Add>proj129@synygy.com</Email_Add>
</Employee>

<Employee>
<Name>Divid Grossberg</Name>
<Title>Managing Consultant</Title>
<Phone_Number>610-494-3300x(7045)</Phone_Number>
<Email_Add>grossberg@synygy.com</Email_Add>
</Employee>
<Employee>
<Name>Peter Lamb</Name>
<Title>Managing Direntor</Title>
<Phone_Number>610-494-3300x(7656)</Phone_Number>
<Email_Add>lamb@synygy.com</Email_Add>
</Employee>
</SynygyCI>

<ccur>
<quarter no="1">
<Credit>210 </Credit>
<TC>180</TC>
</quarter>
<quarter no="2">
<Credit>190 </Credit>
<TC>160</TC>
</quarter>
<quarter no="3">
<Credit>175 </Credit>
<TC>155</TC>
</quarter>
</ccur>

</MyReport>

 

 

 

Thanks a lot in advance.

Link to comment
Share on other sites

If you are using iReport, it has a great XPath tool in it, it will highlight the parent nodes that your XPath query will select.

 

I am not an XPath expert by any means, but you may try the query "/MyReport/*/*" This XPath query will select all fields 2 deep from the root of MyReport.

 

Check w3Schools.com for a good reference.

Post edited by: jwsmith22, at: 2007/08/02 19:30

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