Jump to content
Changes to the Jaspersoft community edition download ×

XML Datasource


2005 IR Help

Recommended Posts

By: LL - lovelyliatroim

XML Datasource

2004-08-04 05:50

Hey Folks,

Just started using the XMLDatasource and trying to get a feel for it, having a few problems though!! have a small xml file like this

<client>

<Accounts>

<Balance type="CashSave "> 111 </Balance>

<Balance type="Deposit"> 888 </Balance>

</Accounts>

</client>

Now i have a field in my report with a field description of "/client/Accounts/Balance", now i have this field in my detail band, problem is that im only getting one record back, just getting an output of 111 and 888 is not being outputted, any one got any idea as to what may be the problem??

 

Now second question is this, how do i, using XPath extract the value of the attribute, take for instance in the above example "type", how do i go about extracting "CashSave" and deposit?? I know if i have /client/Accounts/Balance[@type], this will only get me the "Balance" element value, so is there a way at getting the attribute type value??

Im not fully up to speed with all XPaths functionality but i cant see how that is done using XPath!!

 

cheers for your help,

LL

 

 

 

 

By: Nanda - nandah

RE: XML Datasource

2004-08-04 06:55

/client/Accounts/Balance/@type will give the value of attrib type

 

 

 

 

By: LL - lovelyliatroim

RE: XML Datasource

2004-08-04 08:03

cheers Nanda, that does the job, any ideas on why it only outputs one record???

 

 

 

 

By: Darren Hartford - binarymonk

RE: XML Datasource

2004-08-04 08:16

What happens if you try an xpath like:

 

/client/Accounts/Balance[@type=CashSave]

 

/client/Accounts/Balance[@type=Deposit]

 

The expectation should be returning the value(s) such as ' 111 ' and ' 888 '.

 

 

 

 

 

By: Peter Severin - peter_p_s

RE: XML Datasource

2004-08-04 11:42

Hi,

 

You should check the xmldatasource sample included with the 0.6.0 version. The problem is that you did not specify the initial XPath select expression for the JRXmlDataSource. In your case it should be:

 

/client/Accounts/Balance

 

The result of this select expression will have two nodes as expected. Then, using the Field's description you can extract the desired information from the node:

 

. (point) - will extract the text value from the current node (111, 888)

 

@type - will extract the type attribute from the current node.

 

Beware that there is bug in the current distribution of JasperReports that causes the xml data source to fail to retrieve the xml attributes with some versions of Xalan. The fix is available in CVS. JasperAssistant was also updated to include this bugfix.

 

Best regards,

 

Peter Severin.

 

 

 

 

 

By: LL - lovelyliatroim

RE: XML Datasource

2004-08-05 00:31

Cheers Peter, that was the problem, hadnt specified a initial XPAth, but if i specified the initial path to be just /client, it wont work!! Is this unrealistic to be asking for this ?? i see in the example, what is done is on a new report we create a new data source(or is it just adjusting the view??) with a new initial XPath!!

((net.sf.jasperreports.engine.data.JRXmlDataSource) $P{REPORT_DATA_SOURCE}).dataSource("/Northwind/Orders[CustomerID=" + $F{CustomerID} + &quot]")

 

 

cheers for the help,

LL

 

 

 

 

By: Peter Severin - peter_p_s

RE: XML Datasource

2004-08-15 10:54

Hi,

 

The initial XPath select expression gives the set of nodes that will be iterated by the data source. While iterating, the data source will position itself on the next node from this initial set. Using Field descriptions you can further extract the necessary information from the current node.

 

Now, using the '/client' as an inital select expression will give you the only node in the datasource - the 'client' node. It is perfectly legal and depending on what you want to achieve can be the right thing to do. From here, using the Field's description you can extract the desired information from the node like this:

 

Accounts/Balance[2] - the value of the second Balance node under the first Accounts node.

 

Accounts/Balance[2]/@type - the value of the type attribute of the second Balance node under the first Accounts node.

 

This mode of accessing the information can be useful when there is a known number of nodes in the xml and the layout of the text fields is not necessarily the top-down layout that is normally created by using the details band.

 

Best regards,

 

Peter Severin

 

 

 

 

By: Peter Severin - peter_p_s

RE: XML Datasource

2004-08-15 11:02

To answer your second question regarding the subreport data source expression below.

 

((net.sf.jasperreports.engine.data.JRXmlDataSource) $P{REPORT_DATA_SOURCE}).dataSource("/Northwind/Orders[CustomerID=" + $F{CustomerID} + &quot]")

 

This expression creates a new data source for the subreport from the same document as the one used for the master report. The new data source uses a different XPath select expression that extracts a different set of nodes from that document. The decision to create the subreport/datasource this way is based on the flat layout of the xml file.

 

A subreport data source can also be created by using the current node as the root of the xml document. For more information see the JRXmlDataSource's javadoc.

 

Best regards,

 

Peter Severin.

 

 

 

 

 

By: LL - lovelyliatroim

RE: XML Datasource

2004-08-16 01:13

Cheers Peter, thanks for the help!!

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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