Oracle provides some nice features for working with XML. There is the option of using PL/SQL and the DBMS_XMLQUERY package or the corresponding OracleXMLQuery Java class.
The OracleXMLQuery class provides an API to retrieve the results of an SQL query as XML. Therefore, I developed a class which would use the OracleXMLQuery and write the results to a file. The query was defined in a Spring context file and injected along with the javax.sql.DataSource. Now it came to the task of writing a test to validate if my class was working. Following the popular approach of testing with Spring and JUnit, I created a test class and a corresponding test context file.
Unfortunately the test would not execute and instead I was presented with the following error:
<Line 43, Column 57>: XML-24509: (Error) Duplicated definition for: 'identifiedType'
<Line 43, Column 57>: XML-24509: (Error) Duplicated definition for: 'identifiedType'
<Line 60, Column 28>: XML-24509: (Error) Duplicated definition for: 'beans'
<Line 157, Column 34>: XML-24509: (Error) Duplicated definition for: 'description'
<Line 169, Column 29>: XML-24509: (Error) Duplicated definition for: 'import'
<Line 191, Column 28>: XML-24509: (Error) Duplicated definition for: 'alias'
<Line 220, Column 33>: XML-24509: (Error) Duplicated definition for: 'beanElements'
<Line 235, Column 44>: XML-24509: (Error) Duplicated definition for: 'beanAttributes'
<Line 510, Column 43>: XML-24509: (Error) Duplicated definition for: 'meta'
<Line 518, Column 35>: XML-24509: (Error) Duplicated definition for: 'metaType'
The problem was that the Oracle XDK which provides the XML Java classes makes use of the Oracle xmlparserv2.jar file to parse XML. This has issues with parsing Spring XSD files and produces the above errors. Spring relies on Apache xerces library. Therefore the solution in this case was to configure Spring not to use the Oracle xml parser via a system property.
System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
Adding the above code to my test class' @BeforeClass method fixed the issue.
Informative post thanks for the help. I'm curious though, how do you resolve the XML parser conflict when you deploy to prod or non-prod environment?
ReplyDeleteNot sure I understand you question. Setting the system property resolves the conflict and can be used in prod or non-prod environments.
ReplyDeleteGot it, just setup the same system property on the application server the app is deployed to.
ReplyDeleteThere is an alternative approach, which might be easier if you have a lot of test cases. Outlined in a stackoverflow answer here: http://stackoverflow.com/questions/11578697/using-oracle-xmltype-column-in-hibernate/18282094#18282094
ReplyDelete