Jump to content

Display data from XML dataspurce


ejhellerattc

Recommended Posts

I am trying to display a simple report, in preparation to expand it to a larger report. The problem is that the report is only displaying the first entry in the list. The XML is:

Code:

<UCMData>
<DeviceName name = "Device Name"/>
<Screen name = "HeaderData">
<Label ExternalDocument = "NONE"/>
<NonZeroValues id = "1">
<ScreenName>"Control"</ScreenName>
</NonZeroValues>
<NonZeroValues id = "2">
<ScreenName>"Local Time"</ScreenName>
</NonZeroValues>
</Screen>
</UCMData>

The relevant sections of the JRXML is:

Code:
[code]
<queryString language="xPath">
<![CDATA[/uCMData]]>
</queryString>
<field name="NonZeroValues" class="java.lang.String">
<fieldDescription>
<![CDATA[screen[@name="HeaderData"]/NonZeroValues/ScreenName]]>
</fieldDescription>
</field>

<!--- DETAIL BAND --->
<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement x="19" y="13" width="100" height="18" key="textField" isPrintRepeatedValues="false"/>
<textElement>
<font/>
</textElement>
<textFieldExpression class="java.lang.String">
<![CDATA[$F{NonZeroValues}]]>
</textFieldExpression>
</textField>

 

When I run this (testing in IReports) the report only generates a single line, either "Control" or "Local Time" depending on which is first. The xPath starts at the top of the tree in order for me to able to generate subreports for different "Screen"s. I have tried different layouts in the XML to no avail.

 

Any thoughts are appreciated.

Thanks,

Edward.

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Thanks for the response. I did look at the javadoc and the examples and the XPath docs and tutorials. Maybe there is just something I am missing in the entire concept. From an overall view, I have an application that has many transactional database entry screens, some of which may have all zeros. To save time, paper, etc., we wish to generate reports that only have non-zero values and a header page that has a list of which screens are printed and which are not. As such, in this case (as a test), what I want to generate is a list of the two ScreenNames with NonZeroValues: Control and Local Time.

 

Something like:

 

Control

Local Time

 

If I need to change the layout of the XML or the JRXML, i have control over both.

 

Thanks,

Edward.

Link to comment
Share on other sites

ejhellerattc wrote:

As such, in this case (as a test), what I want to generate is a list of the two ScreenNames with NonZeroValues: Control and Local Time.

 

You should do something like this then:

Code:

<queryString language="xPath">/UCMData/Screen/NonZeroValues</queryString>
<field name="ScreenName">
<fieldDescription>ScreenName</fieldDescription>
</field>

 

HTH,

Lucian

Link to comment
Share on other sites

Lucian,

Thanks. That works for the simple case. However, in the more complex end result, my plan (if JR supports it) is that the XML will have many <Screen> sections with different names. Each <Screen> section will have the data for a specific report template and a master report will be created on the fly to call/display/instantiate the various subreports that are needed, based on user and programmatic selection. Since they will all use the same base of UCMData, I thought that the root node would be UCMData with each subreport finding its specific data from that base path.

 

This, of course, leads to the second part of my problem that I have also not discovered a solution to: How to call the subreports from the master report and pass them the same data source, since that will also be dynamic. I am starting to think that this will need to be passed from my app as a parameter and from the master to the subreports as a parameter as well.

 

Thanks,

Edward.

Link to comment
Share on other sites

If you have more complex scenarios, you'll probably have to resort to subreports in order to iterate on several node sets.

 

For instance, if you want show all Screen sections, and for each Screen all NonZeroValues, you would have a master report that iterates on Screen nodes, and a subreport that iterates on NonZeroValues nodes:

Code:

<!-- master report -->
<queryString>/UCMData/Screen</queryString>
...
<subreportParameter name="XML_DATA_DOCUMENT">
<subreportParameterExpression>
((JRXmlDataSource) $P{REPORT_DATA_SOURCE}).subDocument()
</subreportParameterExpression>
</subreportParameter>

<!-- subreport -->
<queryString>/Screen/NonZeroValues</queryString>

 

 

This, of course, leads to the second part of my problem that I have also not discovered a solution to: How to call the subreports from the master report and pass them the same data source, since that will also be dynamic.

 

You can't pass the same data source to a subrpeort because JR data source are java.util.Iterators or java.sql.ResultSets, i.e. they are consumed by the report that uses them. However, you can reuse the underlying document of an XML data source by creating new data sources via the dataSource() and subDataSource() methods (see the Javadoc), or by passing the same document as XML_DATA_DOCUMENT if you use the XPath query executer.

 

Regards,

Lucian

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