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

XML + iReport newbie question


valfer

Recommended Posts

Ok, I am a newbie trying to build a XML report with the following XML data source:

<?xml version="1.0"?>
<MyFile>
    <Accounts>
        <Account>
            <Ac_Detail>
                    <Op No="1" Amount="100,00" Date="22/1/2010" Cat="25" SubCat="1"/>
                    <Op No="2" Amount="150,00" Date="25/1/2010" Cat="26" SubCat="2"/>
                    <Op No="3" Amount="200,00" Date="31/1/2010" Cat="25" SubCat="2"/>
             </Ac_Detail>
        </Account>
    </Accounts>
    <Category>
          <Cat_Detail>
            <Category No="25" Name="Payment">
                        <SubCategory No="1" Name="Supplier 1"/>
                         <SubCategory No="2" Name="Supplier 2"/>
            </Category>
               <Category No="26" Name="Transfer">
                    <SubCategory No="1" Name="Supplier 3"/>
                     <SubCategory No="2" Name="Supplier 4"/>
            </Category>
         </Cat_Detail>
    </Category>
</MyFile>
 

I' ve followed this tutorial jasperforge.org/website/ireportwebsite/IR%20Website/ir_xml_datasources.html but I want my report to have the following fields: Amount, Date and the Name in the subcategory which as you can see comes from the corresponding Cat and SubCat, so that I can get something like this:

Amount   Date                 Name

100,00    22/01/2010     Supplier 1

150,00    25/01/2010     Supplier 3

200,00    31/01/2010     Supplier 2

I started with a new blank report, setup a datasource pointing to my XML file. Then I went to the Query Editor and set the Query language as XPath and right clicked on the Op node and selected "set record node (generate xPath)", then selected "add node as fields" for the Amount and  Date. So far so good.

Then  selected the Name in subcategory and added that both as "add node as field" and  "add node as field (using absolute path", but no mather what I do I always get Supplier 1 in the Name column.

What am I doing wrong? Must I build a subreport? Can you please help me?

 

Thanks

 

Link to comment
Share on other sites

  • 3 months later...
  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

 Since you want to iterate over each of the Op nodes, don't use the absolute path when setting up the fields.  For example, your XPath for the report should be:

/MyFile/Accounts/Account/Ac_Detail/Op

and the fields should be:

@Amount

@Date

@SubCat

(See attached JRXML for context)

Code:
<?xml version="1.0" encoding="UTF-8"?><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report name" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">	<property name="ireport.zoom" value="1.0"/>	<property name="ireport.x" value="0"/>	<property name="ireport.y" value="0"/>	<queryString language="xPath">		<![CDATA[/MyFile/Accounts/Account/Ac_Detail/Op]]>	</queryString>	<field name="Amount" class="java.lang.String">		<fieldDescription><![CDATA[@Amount]]></fieldDescription>	</field>	<field name="Date" class="java.lang.String">		<fieldDescription><![CDATA[@Date]]></fieldDescription>	</field>	<field name="SubCat" class="java.lang.String">		<fieldDescription><![CDATA[@SubCat]]></fieldDescription>	</field>	<pageHeader>		<band height="28">			<staticText>				<reportElement x="0" y="0" width="100" height="20"/>				<textElement>					<font isBold="true"/>				</textElement>				<text><![CDATA[Amount]]></text>			</staticText>			<staticText>				<reportElement x="100" y="0" width="100" height="20"/>				<textElement>					<font isBold="true"/>				</textElement>				<text><![CDATA[Date]]></text>			</staticText>			<staticText>				<reportElement x="200" y="0" width="100" height="20"/>				<textElement>					<font isBold="true"/>				</textElement>				<text><![CDATA[Name]]></text>			</staticText>		</band>	</pageHeader>	<detail>		<band height="34" splitType="Stretch">			<textField>				<reportElement x="0" y="0" width="100" height="20"/>				<textElement/>				<textFieldExpression class="java.lang.String"><![CDATA[$F{Amount}]]></textFieldExpression>			</textField>			<textField>				<reportElement x="100" y="0" width="100" height="20"/>				<textElement/>				<textFieldExpression class="java.lang.String"><![CDATA[$F{Date}]]></textFieldExpression>			</textField>			<textField>				<reportElement x="200" y="0" width="100" height="20"/>				<textElement/>				<textFieldExpression class="java.lang.String"><![CDATA[$F{SubCat}]]></textFieldExpression>			</textField>		</band>	</detail></jasperReport>
Link to comment
Share on other sites

  • 3 years later...

Hello frds,
Iam new @jasper Report.....i have one requirement ,,,iam enable to get any blog for this so plz help meeeeeee

My requirment is .......i want to do SubTotal for more than 2 rows .So iam unable to get this .Soooo plz help and send step how to do this...

Plz check below attached Excel File like tht i want output............Iam waiting for Your Reply.

 

Regards

Gopal Reddy

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