Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
BIRT // XML Data Source and Data Set
gsemalty
<p>Hello,</p>
<p> </p>
<p>Can someone help me ... I have to use following type of XML Data file and present data in Report.</p>
<p>
</p>
<div><?xml version="1.0" encoding="iso-8859-1"?></div>
<div><tickets></div>
<div> </div>
<div> <ticket ticketType="2" serviceId="102"></div>
<div> <tag eventId="3100.2.11.2" name="Called Number" dump="12345678"/></div>
<div> <tag eventId="3100.2.112.1" name="Date Time Of Event" dump="30/10/2015 13:49:25"/></div>
<div> <tag eventId="3100.2.11.1" name="Numbering Format Of Called Number" dump="ABC"/></div>
<div>
<div> </ticket></div>
<div> </div>
<div>
<div> <ticket ticketType="2" serviceId="102"></div>
<div> <tag eventId="3100.2.11.2" name="Called Number" dump="87654321"/></div>
<div> <tag eventId="3100.2.112.1" name="Date Time Of Event" dump="03/01/2015 13:49:25"/></div>
<div> <tag eventId="3100.2.11.1" name="Numbering Format Of Called Number" dump="DEF"/></div>
<div> </ticket></div>
</div>
<div> </div>
<div></tickets></div>
<div> </div>
<div>1) One issue I noted using XML Data Source was that this XML has same <tag> element at same level.</div>
<div>I found in one of the post that this can be solved using "Scripted Data Source and Data Set". I downloaded the example.</div>
<div> </div>
<div>2) But second issue is that my xml tag is of type :-</div>
<div> </div>
<div> <tag eventId="3100.2.11.2" name="Called Number" dump="87654321"/></div>
<div> </div>
<div>So I am not able to fetch the "attribute" like eventId / name / dump</div>
<div> </div>
<div>Please help or suggest some example to parse the following XML.</div>
</div>
<p> </p>
Find more posts tagged with
Comments
gsemalty
<p>The scripted data source example, I downloaded for sample, had following FETCH script.</p>
<p>But It cannot extract attribute from XML tag element.</p>
<p> </p>
<p>====================================================</p>
<div>if (x < cnt2)</div>
<div>{</div>
<div>var nodeList = nodes2.item(x).getChildNodes();</div>
<div>var nodeListLength = nodes2.item(x).getChildNodes().getLength();</div>
<div>for(var i=0; i<nodeListLength; i++){</div>
<div>var nodeName = nodeList.item(i).getNodeName();</div>
<div>var nodeText = nodeList.item(i).getTextContent();</div>
<div>if(nodeName == "title"){<span> </span></div>
<div>row["Title"] = nodeText;</div>
<div>}else if(nodeName == "copies"){</div>
<div>row["Copies"] = nodeText;</div>
<div>}else if(nodeName == "price"){</div>
<div>row["Price"] = nodeText;</div>
<div>}else if(nodeName == "author"){</div>
<div>if(row["Author"]){</div>
<div>//Detect if this row has already received an author and then append next author to the end with a space seperator.</div>
<div>row["Author"] = row["Author"] + " & " + nodeText;</div>
<div>}else{</div>
<div>row["Author"] = nodeText;</div>
<div>}</div>
<div>}</div>
<div>}</div>
<div>x++;</div>
<div>return (true);</div>
<div>}</div>
<div> </div>
<div> </div>
<div>return (false);</div>
Clement Wong
<p>If you are using a <strong>Scripted Data Source</strong>, then you can use the technique of my DevShare example that illustrates parsing XML with the built-in function E4X @ <a data-ipb='nomediaparse' href='
http://developer.actuate.com/community/forum/index.php?/files/file/1122-parsing-xml-in-birt-with-e4x/'>http://developer.actuate.com/community/forum/index.php?/files/file/1122-parsing-xml-in-birt-with-e4x/</a></p>
;
<p> </p>
<p>Attached is an example with your XML. Take a look at the <em>beforeOpen</em>, <em>open </em>and <em>fetch </em>events of the Scripted Data Set.</p>
<pre class="_prettyXprint">
row["Called Number"] = tickets.ticket[currentrow].tag.(
@name
== "Called Number").
@dump
.toString();
row["Date Time Of Event"] = tickets.ticket[currentrow].tag.(
@name
== "Date Time Of Event").
@dump
.toString();
row["Numbering Format Of Called Number"] = tickets.ticket[currentrow].tag.(
@name
== "Numbering Format Of Called Number").
@dump
.toString();
</pre>
<p>Now, if you want to use the<strong> XML Data Source</strong>...</p>
<p> </p>
<p>Then, you can define your Row Mapping as:</p>
<p style="margin-left:40px;"><span style="font-family:'courier new', courier, monospace;">/tickets/ticket</span></p>
<p> </p>
<p>And the Column Mapping as follows:</p>
<p style="margin-left:40px;"><span style="font-family:'courier new', courier, monospace;">/tag[
@name=
'Called Number']/
@dump<
;/span></p>
<p style="margin-left:40px;"><span style="font-family:'courier new', courier, monospace;">/tag[
@name=
'Date Time Of Event']/
@dump<
;/span></p>
<p style="margin-left:40px;"><span style="font-family:'courier new', courier, monospace;">/tag[
@name=
'Numbering Format Of Called Number']/
@dump<
;/span></p>
<p> </p>
<p>Or the Column Mapping as follows (assuming that the position of the tag/names do not change):</p>
<p style="margin-left:40px;"><span style="font-family:'courier new', courier, monospace;">/tag[1]/
@dump<
;/span></p>
<p style="margin-left:40px;"><span style="font-family:'courier new', courier, monospace;">/tag[2]/
@dump<
;/span></p>
<p style="margin-left:40px;"><span style="font-family:'courier new', courier, monospace;">/tag[3]/
@dump<
;/span></p>