Issues with XML Data source

Options
ushank
edited February 11, 2022 in Analytics #1
<p>I have to use an XML as a data source in my report.<br>
My xml has multiple child tags with the same name(ex. <author>). Please refer the XML pasted below.</p>
<p> </p>
<p><em><?xml version="1.0" encoding="ISO-8859-1"?></em></p>
<p><em><BookStore><br>
<Book><br>
<title>History</title><br>
<author>Tom</author><br>
<copies>10;</copies><br>
<price>80</price><br>
</Book></em></p>
<p><em><Book><br>
<title>Basic Mathematics</title><br>
<author>Roy</author><br>
<author>Jon</author><br>
<copies>5</copies><br>
<price>100</price><br>
</Book></em></p>
<p><em><Book><br>
<title>Java</title><br>
<author>Harry</author><br>
<author>Potter</author><br>
<copies>6</copies><br>
<price>100</price><br>
</Book><br>
</BookStore></em></p>
<p> </p>
<p>I have added a XML data source and a dataset in my report. I have made the following mappings in my XML dataset.</p>
<p>Row mapping: /BookStore/Book<br>
Column Mapping: Mapped all the child tags</p>
<p>
In the data set, I am getting three records, one for each of the <Book> tag. But, the author column contains the value of only the first tag.For example, the second record contains only "Roy". The second <author> tag is not being recognised by the BIRT. I need to get both "Roy" & "Jon" from the second <Book> element. And, I need  to get both "Harry" & "Potter" from the third <Book> element. Can you please let me know how to get all the values from tags with the same name into the dataset.</p>
<p>I have attached the rpt design file and xml source I'm using.</p>
<p>Appreciate your help. Please let me know how to design the XML dataset.</p>

Comments

  • <p>rptdesign file</p>
    <p>
  • <p>The out of the box ODA for XML has limitations when it comes to more complex XML such as situations like this where you can have a varying number of nodes with the same name.</p>
    <p> </p>
    <p>Instead you can create a scripted data source/set and write the needed logic to parse the XML into your desired rows.</p>
    <p> </p>
    <p>Take a look at the attached modified version of your sample Book report I have attached with an example of doing this with a scripted data source/set.</p>
    Warning No formatter is installed for the format ipb
  • <p>Hey Jesse, you are my saviour.. The code helped me nail the issue I was facing. Thanks a lot for your help.  Was really busy over the past few weeks. Just realised that I did not even say a thanks to you. Thanks a ton for your timely response.</p>
  • <p>You're welcome, I'm glad I could be of assistance.</p>
    <p>Thank you for taking the time to confirm this helped resolve the issue.</p>
    <p> </p>
    <p>Let us know if you have additional questions in the future.</p>
    Warning No formatter is installed for the format ipb
  • Sandy Wishpond
    edited March 21, 2017 #6
    Options
    <p>Along the same lines is it possible to form rows (rather than appending the data together), eg:</p>
    <p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"><em><?xml version="1.0" encoding="ISO-8859-1"?></em></p>
    <p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"><em><BookStore><br>
    <Book><br>
           <title>History</title></em></p>
    <p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"><em>       <title>Science</title><br>
           <author>Tom</author><br>
            <author>Kevin</author><br>
    </Book></em></p>
    <p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"><em><BookStore></em></p>
    <p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> </p>
    <p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"><em>then is it possible to display data under a table as:</em></p>
    <p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"><em>Book Title       Book Author</em></p>
    <p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"><em>History            Tom</em></p>
    <p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"><em>Science            Kevin</em></p>
    <p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> </p>