Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Exception from Serializer.fromXml()
elliotkatz
Hi,
I am trying to create a org.eclipse.birt.chart.model.Chart object from an xml file using Serializer.fromXml()
My code for reading is: (ignoring Exceptions)
org.eclipse.birt.chart.model.Chart chartFromFile(File xmlFile)
{
FileInputStream fis = new FileInputStream(xmlFile);
int nBytes = (int)(xmlFile.length()); //(The file length fits into an int)
byte[] buf = new byte[nBytes+1];
int nRead = fis.read(buf);
ByteArrayInputStream baStream = new ByteArrayInputStream(buf);
Serializer ser = SerializerImpl.instance();
// The next line throws an Exception
org.eclipse.birt.chart.model.Chart birtChart = ser.fromXml(baiStream, true); //(I tried true and false)
fis.close();
return birtChart;
}
I always get the following Exception:
org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Content is not allowed in trailing section.
(I am running in IBM RAD 7.0 - Eclipse-based)
My xml files have an <model:ChartWithAxes> element as the outermost element.
I have tried generating the xml in two ways:
1) I created an .rptdesign file in the BIRT designer (2.3.0). I then extracted the chart from the file and saved it as an xml.
2) I use the API to create a org.eclipse.birt.chart.model.Chart object and then used Serializer.asXml() to create an xml file:
private void writeXml(Chart chart)
{
Serializer s = SerializerImpl.instance();
ByteArrayOutputStream st = s.asXml(chart, true);
String xml = st.toString();
PrintWriter pw = new PrintWriter(new FileWriter("c:/BIRT/Reports/test.xml"));
pw.println(xml);
pw.close();
}
Either way, I throw an Exception when I try to read the xml.
(BTW, I am able to parse the xml file using javax.xml.parsers.DocumentBuilder)
Does anyone know what I am doing wrong?
Thanks,
Elliot Katz
(I got a database error when I submitted the first time. I hope this doesn't show up as a duplicate post)
Find more posts tagged with
Comments
mwilliams
Hi Elliot,
So, you are just getting this error when you're trying to read the generated XML? If so, can you attach one of the XML files you have that you're getting this problem with?