Home
Analytics
[BIRT 2.6] Nested XML data
dword
Hi all,<br />
I've looked arround to find out any solution to my simple problem without any clear solution.<br />
I'm working from an XML data source like this one:<br />
[XML]<Item name="Test Item 1" ID="1"><br />
<Property name="Prop 1" value="12345"/><br />
<Subs><br />
<Subitem name="sub 1_1"/><br />
<Subitem name="sub 1_2"/><br />
<Subitem name="sub 1_3"/><br />
<Subitem name="sub 1_4"/><br />
</Subs><br />
<Color>Red</Color><br />
</Item><br />
<Item name="Test Item 2" ID="2"><br />
<Property name="Prop 1" value="12345"/><br />
<Subs><br />
<Subitem name="sub 2_1"/><br />
<Subitem name="sub 2-2"/><br />
</Subs><br />
<Color>Blue</Color><br />
</Item>[/XML]<br />
<br />
So what I want to have in my report is a table lisiting:<br />
<br />
<br />
* all the items<br />
* for each item all its subitems<br />
<br />
Any idea on how to do that?<br />
<br />
Thank you!
Find more posts tagged with
Comments
bhanley
Using the XML Data Source you should be able to use simple XPath to define each column in your table. You set the initial XPath query to define a row to go to "Item" (/Item). From there you collect the values you need for each row in the table. The queries from this point are relative to each Item node.
Then in the table you can group on Item Name or any other value you like to organize the data and make it a little easier to read.
Good Luck!
dword
<blockquote class='ipsBlockquote' data-author="'bhanley'" data-cid="67473" data-time="1282140418" data-date="18 August 2010 - 07:06 AM"><p>
Using the XML Data Source you should be able to use simple XPath to define each column in your table. You set the initial XPath query to define a row to go to "Item" (/Item). From there you collect the values you need for each row in the table. The queries from this point are relative to each Item node. <br />
<br />
Then in the table you can group on Item Name or any other value you like to organize the data and make it a little easier to read.<br />
<br />
Good Luck!<br /></p></blockquote>
Hi Brian, thank you for your answer. I did a query that is listing each item, but for each item you may have several subitems, not only a single one. I have no clue on how to have it listed/displayed. Of coure I can't just add a "/Subs" xpath query.<br />
Since each line of "item" can have one or several lines of "subitems" I don't know how to set up my query properly. My understanding it that I may require an extra query to list "subitems" and somehow merge that data with the one comming from "items" query. <br />
Thank you for your help!
dword
I've tried to look at scripted data sources, but can't find any solution to what sounds a trivial problem. Am I the only one to have this issue?
Wenjie
First, you should clarify what xml elements are going to be mapped as rows and what element values or attributes are going to be mapped as columns.
For you case, maybe you can define following row/column mapping path:
row mapping: //Subitem
column1("Subitem_name") mapping:
@name
column2("Item_name") mapping: ../../
@name
column3("Item_color") mapping: ../../Color
....
dword
<blockquote class='ipsBlockquote' data-author="'Wenjie'" data-cid="67555" data-time="1282273724" data-date="19 August 2010 - 08:08 PM"><p>
First, you should clarify what xml elements are going to be mapped as rows and what element values or attributes are going to be mapped as columns.<br />
<br />
For you case, maybe you can define following row/column mapping path:<br />
row mapping: //Subitem<br />
column1("Subitem_name") mapping:
@name<
;br />
column2("Item_name") mapping: ../../
@name<
;br />
column3("Item_color") mapping: ../../Color<br />
....<br /></p></blockquote>
Oh, I see, your are listing all "subitems" and you're geting its parent "items" attributes. I guess it's a solution to do what I want
Of course it will duplicate parent's name and color for each row, but I may find a way to deal with it. Thank you!