Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-08-2010, 08:20 PM   PM User | #1
sumanta
New Coder

 
Join Date: Oct 2009
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
sumanta is an unknown quantity at this point
The character '' is an invalid XML character expection

Dear All,

I am extract data from database and export in XML file.

If in the database table contains less than 8000 records then the xml generated successfully.

But if the record contains more than 8000 records while export data in xml file it is throwing the exception

ERROR [main] - Error in xmlExport
java.io.IOException: The character '' is an invalid XML character
at org.apache.xml.serialize.BaseMarkupSerializer.characters(Unknown Source)
at com.siemens.plmwbs.dao.ExportPlmWbsDao.generateXMLFile(ExportPlmWbsDao.java:137)
at com.siemens.plmwbs.dao.ExportPlmWbsDao.getFileData(ExportPlmWbsDao.java:252)
at com.siemens.plmwbs.exportwbs.PLMWbsExporter.generatePLMWBSXMLFile(PLMWbsExporter.java:100)
at com.siemens.plmwbs.exportwbs.PLMWbsExporter.main(PLMWbsExporter.java:67)


Below given the code:-


private static String selectEZXfileXMLRow=
"SELECT top 9000 "
+"WBS_ELEMENT_ID,"
+"WBS_ELEMENT_DESC,"
+"WBS_PROFIT_CTR,"
+"PROJ_DEFINITION,"
+"PROJ_DESC,"
+"PROJ_PROFIT_CENTER,"
+"PER_NR "
+" FROM "
+" INBOUND_SAP_WBS_ELEMENTS WITH(NOLOCK) ";


/**This method generates XML file */
private BaseVo generateXMLFile(
ConnectionManager con,
String sqlXMLQuery,
String fileName,
BaseVo baseVo,
PLMWbsCons plmWbsCons) throws Exception
{
String wbselementid = "";
String wbselementdesc = "";
String wbsprofitctr="";
String projdefination="";
String projdesc="";
String projprofitcenter="";
String pernr="";
int i = 0;

FileOutputStream fos = null;
OutputFormat of = null;
ContentHandler hd = null;
AttributesImpl atts = null;




try
{
PreparedStatement ps = con.getPreparedStatement(sqlXMLQuery);
ResultSet rs = con.executeQuery();
//System.out.println("No of records found are ####### " +rs.getFetchSize());

File xmlFile = new File(Constants.getProperty("EZX_GENERATED_FILE")
+ "/"
+ fileName);


fos = new FileOutputStream(xmlFile);
of = new OutputFormat("XML", "UTF-8", true);
of.setIndent(1);
of.setIndenting(true);
XMLSerializer serializer = new XMLSerializer(fos, of);
// SAX2.0 ContentHandler.
hd = serializer.asContentHandler();
hd.startDocument();
atts = new AttributesImpl();

hd.startElement("", "", "MT_WBS_Elements_File_In", atts);
while(rs.next())

{
//------------Row Details Start here------------------

hd.startElement("", "", "WBS_Elements", atts);
if(rs.getString("WBS_ELEMENT_ID") != null)
{
wbselementid = rs.getString("WBS_ELEMENT_ID");
}
if(wbselementid==null)wbselementid="";
atts.addAttribute("", "", "Length", "CDATA", "24");
hd.startElement("", "EZX", "WBS_Element_ID", atts);
//atts.addAttribute("", "", "Length", "CDATA", wbselementid);
hd.characters(wbselementid.toCharArray(), 0, wbselementid.length());
hd.endElement("", "", "WBS_Element_ID");
atts.clear();
if(rs.getString("WBS_ELEMENT_DESC") != null)
{
wbselementdesc = rs.getString("WBS_ELEMENT_DESC");
}
if(wbselementdesc==null)wbselementdesc="";
atts.addAttribute("", "", "Length", "CDATA", "40");
hd.startElement("", "EZX", "WBS_Element_Description", atts);
hd.characters(wbselementdesc.toCharArray(), 0, wbselementdesc.length());
hd.endElement("", "", "WBS_Element_Description");
atts.clear();
if(rs.getString("WBS_PROFIT_CTR") != null)
{
wbsprofitctr = rs.getString("WBS_PROFIT_CTR");
}
if(wbsprofitctr==null)wbsprofitctr="";
atts.addAttribute("", "", "Length", "CDATA", "10");
hd.startElement("", "EZX", "WBS_Profit_Center", atts);
hd.characters(wbsprofitctr.toCharArray(), 0, wbsprofitctr.length());
hd.endElement("", "", "WBS_Profit_Center");

atts.clear();
if(rs.getString("PROJ_DEFINITION") != null)
{
projdefination = rs.getString("PROJ_DEFINITION");
}
if(projdefination==null)projdefination="";
atts.addAttribute("", "", "Length", "CDATA", "24");
hd.startElement("", "EZX", "Project_Definition", atts);
hd.characters(projdefination.toCharArray(), 0, projdefination.length());
hd.endElement("", "", "Project_Definition");
atts.clear();
if(rs.getString("PROJ_DESC") != null)
{
projdesc = rs.getString("PROJ_DESC");
}
if(projdesc==null)projdesc="";
atts.addAttribute("", "", "Length", "CDATA", "40");
hd.startElement("", "EZX", "Project_Description", atts);
hd.characters(projdesc.toCharArray(), 0, projdesc.length());
hd.endElement("", "", "Project_Description");
atts.clear();
if(rs.getString("PROJ_PROFIT_CENTER") != null)
{
projprofitcenter = rs.getString("PROJ_PROFIT_CENTER");
}
if(projprofitcenter==null)projprofitcenter="";
atts.addAttribute("", "", "Length", "CDATA", "10");
hd.startElement("", "EZX", "Project_Profit_Center", atts);
hd.characters(projprofitcenter.toCharArray(), 0, projprofitcenter.length());
hd.endElement("", "", "Project_Profit_Center");
atts.clear();
if(rs.getString("PER_NR") != null)
{
pernr = rs.getString("PER_NR");
}
if(pernr==null)pernr="";
atts.addAttribute("", "", "Length", "CDATA", "10");
hd.startElement("", "EZX", "SAP_Personal_Number", atts);
hd.characters(pernr.toCharArray(), 0, pernr.length());
hd.endElement("", "", "SAP_Personal_Number");

hd.endElement("", "", "WBS_Elements");
atts.clear();
i++;
}

//System.out.println("The i value is"+i);
hd.startElement("", "", "Control_Totals", atts);
atts.addAttribute("", "", "Length", "CDATA", "13");
hd.startElement("","","WBS_Count",atts);
hd.characters(String.valueOf(i).toCharArray(), 0, String.valueOf(i).length());
//hd.characters(String.valueOf(i).toCharArray(), 0, String.valueOf(i).length());
hd.endElement("","","WBS_Count");
hd.endElement("", "", "Control_Totals");
hd.endElement("", "", "MT_WBS_Elements_File_In");

hd.endDocument();


}
catch (Exception e)
{
//baseVo.setStatusCode("1014");
//SendEMail.sendMail(baseVo);
log.error("Error in xmlExport", e);
}


finally
{
fos.close();

}

return baseVo;
}


Please suggest how to fix this error.

Thanks in advance.

Regards,
Sumanta Panda
sumanta is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:09 PM.


Advertisement
Log in to turn off these ads.