Parse XML from Database Field in BIRT Report

Options
Virgil Dodson
Virgil Dodson E admin
edited July 28, 2021 in Analytics #1
This example selects a String of XML from a database field, and then parses that string into several fields for the report. The code in this example is found in the computed columns of the Data Set as well as an expression of a data element and looks like the code below.<br />
<br />
Javascript code to parse the XML:
importPackage(Packages.org.apache.xerces.parsers);
importPackage(Packages.org.xml.sax);
importPackage(Packages.java.io);

var parser = new DOMParser();
parser.parse(new InputSource(new StringReader(dataSetRow&#91;"student_property"])));
var nodelist = parser.getDocument().getElementsByTagName('firstname');
var entry = nodelist.item(0).getFirstChild().getNodeValue();

entry;
<br />
This example was created with BIRT 2.2
Warning No formatter is installed for the format ipb