Removing newline character from XML input file to SAX parser
Gemini Moses
Ranch Hand
Joined: Jan 04, 2001
Posts: 244
posted
0
I have written SAX parser in Java to parse an XML file.
<root> <dept> <id>111</id> <name>aaa</name> <description>this is for all accounts purpose. only for south zone does not take care of consolidated accounts. </description> </dept> <dept> <id>222</id> <name>ppp</name> <description>this is for all HR purpose. only for south zone does not take care of consolidated accounts.
</description> </dept> </root>
By parsing this file I am creating Insert statments to insert this data to Oracle.
First row and rows similar to that are getting parsed and inserted with no problem.
When I remove this additional line from the datat file manually, the program works fine.
How do I achieve this programatically.
Here is
public void characters(char[] ch, int start, int length) throws SAXException { if (thisElement !="root"){ if ((length == 0) && (thisElement !="") ){ table_name = thisElement; sql = " Insert into "+ table_name +"("; value_clause=""; value_clauseBuffer =null; columnNames = ""; }
if ((length != 0) && (thisElement!="") && (thisElement!=table_name)){ String s = new String(ch, start, length); String newString = s.replaceAll("'", "''"); /* This is where I was thinking I need some way of removing newline character */ if (value_clauseBuffer== null){ value_clauseBuffer = new StringBuffer(s); } else{ value_clauseBuffer.append(s); } }