The application model is UI<->JavaServerside<->Oracle StoredProcedures[DB]
I retrieve the XML data received from the Stored procedure XML-Out and pass it to the UI as a JSON object.
Here's the snippet.
import oracle.xdb.XMLType;
import org.json.JSONObject;
XMLType studentsdataXML = null;
JSONObject xmlJSONObj = null;
studentsdataXML = (XMLType) callableStatement.getObject(5);
String xmlString = studentsdataXML.getString();
xmlJSONObj = XML.toJSONObject(xmlString); // using org.json library
//return xmlJSONObj ;
The above code works well, converts the XML to JSON object , BUT the performance issue is when performing the studentsdataXML.getString() It takes about 3/4th of total execution time[from UI back to UI].
Question is whether I can do a direct XML to JSON conversion? [oracle.xdb.XMLType to JSON object] or any suggestions for different library that can do this
org.json library used: http://www.json.org/java/
Update1: Updating the getString() to getStringVal()
ie: String xmlString = studentsdataXML.getStringVal();
getStringVal() - http://docs.oracle.com/cd/B28359_01/appdev.111/b28391/oracle/xdb/XMLType.html#getStringVal__
This article recommends to use getStringVal() to get the string value - http://docs.oracle.com/cd/B19306_01/appdev.102/b14259/xdb11jav.htm#g1039140
Also, Time measuring snippet:
...
long stime1 = System.currentTimeMillis();
String xmlString = studentsdataXML.getStringVal();
long etime1 = System.currentTimeMillis();
log.info("Total time (in ms) for XML object to String conversion : " + (etime1 - stime1));
long stimexml = System.currentTimeMillis();
xmlJSONObj = XML.toJSONObject(xmlString);
long etimexml = System.currentTimeMillis();
log.info("Total time (in ms) for XML String to JSON conversion : " + (etimexml - stimexml));
...Total time (in ms) for execute query to retreive XML : 1308
Total time (in ms) for XML object to String conversion : 31452
Total time (in ms) for XML String to JSON conversion : 423
Update2: Another SO thread with somehwat similar issue, but unaswered- Slow to convert Oracle 11g XMLType into Java String or Document
Update3:
When I call the getStringVal() after closing the connection, I get the exception - java.sql.SQLRecoverableException: Closed Connection
studentsdataXML.getString();execution - spiderman