Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Processing XML files that contain Special Characters

62274Apr 10 2002
Hello:

Before I explain my problem I think I should briefly explain what I am trying to do. I have a JSP page that invokes a Java method (the code is attached). This java method takes in an XML file and an XSLT file. It parses the XSLT and also the XML file. If the parsing went through fine, it then processes the XML file and applies the XSLT to the XML file and returns a XMLDocumentFragment Object back to JSP and the JSP renders it.

This mechanism works well. However off late I have encountered a few XML files containing characters such as &Ecirc (Capital E with circumflex accent). Whenever my Java method tries to parse/process this .xml file it gives me the following error.

ORG.oclc.da.utilities.ifs.ReportException: An Error Occured While Parsing the Report: Missing entity 'Ecirc'. at ORG.oclc.da.archive.userinterface.ReportHelper.retrieveReport(Unknown Source) at /ViewReport.jsp._jspService(/ViewReport.jsp.java:87) (JSP page line 65) at com.orionserver[Oracle9iAS (1.0.2.2) Containers for J2EE].http.OrionHttpJspPage.service(OrionHttpJspPage.java:54) at com.evermind[Oracle9iAS (1.0.2.2) Containers for J2EE].server.http.HttpApplication.serviceJSP(HttpApplication.java:5458) at com.evermind[Oracle9iAS (1.0.2.2) Containers for J2EE].server.http.JSPServlet.service(JSPServlet.java:31) at com.evermind[Oracle9iAS (1.0.2.2) Containers for J2EE].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:501) at com.evermind[Oracle9iAS (1.0.2.2) Containers for J2EE].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:170) at com.evermind[Oracle9iAS (1.0.2.2) Containers for J2EE].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:576) at com.evermind[Oracle9iAS (1.0.2.2) Containers for J2EE].server.http.HttpRequestHandler.run(HttpRequestHandler.java:189) at com.evermind[Oracle9iAS (1.0.2.2) Containers for J2EE].util.ThreadPoolThread.run(ThreadPoolThread.java:62)

It seems like the Oracle Parser/XSLT Processor (oracle.xml.parser.v2.DOMParser) I am using is not able to handle special characters such &Ecirc. I was wondering if there is anyway around this problem.

Attached is the Java Method that handles both the parsing and processing of the XML file.


/** The method parses the Report Data and applies the Style Sheet to this data
*
* @param The InputStream (Report Contents - .xml file), Name of the StyleSheet that needs to be applied
* @return A sub-section of the report data (DOM DocumentFragment is returned)
*/
private XMLDocumentFragment parseReport(InputStream reportStream,String strStyleSheet) throws Exception
{
DOMParser parser;
XMLDocument xml, xsldoc, out;
URL urlStyleSheet;

//Get the URL for the Style Sheet
urlStyleSheet = new URL(strStyleSheet);

//Create an instance of the Dom Parser
parser = new DOMParser();
parser.setPreserveWhitespace(true);

//Parse the XSL document and create a DOM Object
parser.parse(urlStyleSheet);
xsldoc = parser.getDocument();
//Parse the report document (a .xml) and create a DOM Object
parser.parse(reportStream);
xml = parser.getDocument();

// instantiate a stylesheet
XSLStylesheet xsl = new XSLStylesheet(xsldoc, urlStyleSheet);

XSLProcessor processor = new XSLProcessor();

// display any warnings that may occur
processor.showWarnings(true);
// processor.setErrorStream(System.err);

// Process XSL
XMLDocumentFragment result = processor.processXSL(xsl, xml);

return result;
}



If you have any suggestions please let me know. If you need more information I will be to furnish it.

thanks
Mathangi
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 9 2002
Added on Apr 10 2002
2 comments
674 views