Large XML Parsing
Please Login to Remove!
Connection code for Getting xml data from URL:
HttpConnection connection = null;
connection =(HttpConnection) Connector.open(url, Connector.READ_WRITE, true);
connection.setRequestMethod(HttpConnection.GET);
connection.setRequestProperty("Content-Type","application/vnd.syncml+xml");
connection.setRequestProperty("Content-Length",String.valueOf(0));
connection.setRequestProperty("User-Agent","Profile/microedition.profiles Configuration/microedition.configuration");
connection.setRequestProperty("Content-Language","microedition.locale");
System.out.println("Connection getResponseCode==="+connection.getResponseCode());
try
{
connection = parsing.getHttpConnection(url);
inputStream = connection.openInputStream();
}catch(Exception e)
{
System.out.println("Connection getResponseCode=== "+e.getMessage());
e.printStackTrace();
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try
{
byte[] buffer = new byte[10000];
int bytesRead = inputStream.read(buffer);
while (bytesRead > 0) {
baos.write(buffer, 0, bytesRead);
bytesRead = inputStream.read(buffer);
}
baos.close();
String result=baos.toString();
ByteArrayInputStream bais =
new ByteArrayInputStream(result.getBytes());
flightSchedule = getXMLObjects(bais);
}
catch (Exception e) {
// TODO: handle exception
}
Parsing Xml data code:
static FlightSchedule getXMLObjects(InputStream is) throws
ParserConfigurationException {
FlightScheduleXML xmlObjectHandler = new FlightScheduleXML();
try {
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
parser.parse(is, xmlObjectHandler);
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return xmlObjectHandler.getFlightSchedule();
}
If Xml data is large parsing is not working,
Some limited Xml data means its working fine.
Any help to solve this issue....
Thanks in Adv,
Venkateshkumar
|