Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: The character '' is an invalid XML character exception getting

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default The character '' is an invalid XML character exception getting

    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.char acters(Unknown Source)
    at com.siemens.plmwbs.dao.ExportPlmWbsDao.generateXML File(ExportPlmWbsDao.java:137)
    at com.siemens.plmwbs.dao.ExportPlmWbsDao.getFileData (ExportPlmWbsDao.java:252)
    at com.siemens.plmwbs.exportwbs.PLMWbsExporter.genera tePLMWBSXMLFile(PLMWbsExporter.java:100)
    at com.siemens.plmwbs.exportwbs.PLMWbsExporter.main(P LMWbsExporter.java:67)


    private static String selectEZXfileXMLRow=   
              "SELECT  "  
              +"WBS_ELEMENT_ID,"  
              +"WBS_ELEMENT_DESC,"  
              +"WBS_PROFIT_CTR,"  
              +"PROJ_DEFINITION,"  
              +"PROJ_DESC,"  
              +"PROJ_PROFIT_CENTER,"  
              +"PER_NR "  
              +" FROM  "    
              +" INBOUND_TEST 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


  2. #2
    Junior Member
    Join Date
    Jan 2010
    Posts
    11
    Thanks
    0
    Thanked 3 Times in 2 Posts

    Default Re: The character '' is an invalid XML character exception getting

    please refer to this link and tell me if it helps

    Java Technology & XML - invalid XML character in castor XML

  3. #3
    Junior Member
    Join Date
    Jan 2010
    Posts
    11
    Thanks
    0
    Thanked 3 Times in 2 Posts

    Default Re: The character '' is an invalid XML character exception getting

    @http://forums.sun.com/thread.jspa?threadID=5352681@

  4. #4
    Junior Member
    Join Date
    Jan 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: The character '' is an invalid XML character exception getting

    Dear Vkumar,

    I have gone through the link which is provided by you(Topic:-invalid XML character in castor XML).
    i facing problem to understand this topic.

    I am a begineer for XML programmer.

    Could you please suggest me in the below given code what is the piece code i need to change so that it should work.


    Thanks for your time.

    Regards,
    Sumanta Panda

  5. #5
    Junior Member
    Join Date
    Jan 2010
    Posts
    11
    Thanks
    0
    Thanked 3 Times in 2 Posts

    Default Re: The character '' is an invalid XML character exception getting

    sumanta

    this problem doesnot seem to be related to the number of rows as it should never matter

    can you attach a sample of xml you r trying to create.Moreover this problem would not be to do with the number of rows

    can i suggest you to delete the 8001 th row and check if the program works. i would thing the row where you have a problem, the data does contain a character which cannot be placed in an xml

  6. #6
    Junior Member
    Join Date
    Jan 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: The character '' is an invalid XML character exception getting

    Dear vkumar23,

    Thanks vkumar23 for your response.The character is an invalid XML character exception issue has been solved.This issue happened because of'the table record.

    When i remove this record from table.It is working.


    One more issue i am facing.

    My table contains 82704 correct records.I didnt get any error/exception while export in xml file.

    While export, few records is export in the xml file .But from the end few records is not exported.

    While open the generated xml file in the end the error message is showing

    "THE XML PAGE CANNOT BE DISPLAYED"
    NOT ENOUGH STORAGE IS AVAILABLE TO COMPLETE THIS OPEARTION"


    Please note that the location of the xml file contains enough space.

    But how many maximum record we export in the xml file at a time.

    The generated xml file size is 44.1 mb.

    Please suggest how i resolve this issue.

    Thanks for the understaning.

    Regards,
    Sumanta Panda
    Last edited by sumanta; January 9th, 2010 at 01:29 PM.

Similar Threads

  1. Replies: 5
    Last Post: April 22nd, 2013, 07:27 AM
  2. need to know if the object is a number or character
    By karneson05 in forum Java SE APIs
    Replies: 8
    Last Post: November 27th, 2009, 10:24 AM
  3. Vietnamese Character Problem in JSP Report. Chinese and Thai Char OK
    By mrvora in forum JavaServer Pages: JSP & JSTL
    Replies: 7
    Last Post: October 23rd, 2009, 02:35 AM
  4. [SOLVED] Getting Exception " java.util.InputMismatchException" in scanner package
    By luke in forum File I/O & Other I/O Streams
    Replies: 10
    Last Post: May 20th, 2009, 04:55 AM
  5. How to read character from image area(jpg image)?
    By sundarjothi in forum Java Theory & Questions
    Replies: 5
    Last Post: August 6th, 2008, 02:08 AM