Wednesday, 12 October 2011

Using Oracle XMLQuery and XML-24509: (Error) Duplicated Definition

Recently I was asked to investigate how static configuration data between multiple deployments of an enterprise application could be managed more easily. The requirement was to be able to extract the required information form an Oracle database so that configuration data between two deployments could be compared. Additionally, if the configuration data along with the relationship between tables could be captured, it would streamline the process of populating a database for a new deployment.

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 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.

4 comments:

  1. 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?

    ReplyDelete
  2. Not sure I understand you question. Setting the system property resolves the conflict and can be used in prod or non-prod environments.

    ReplyDelete
  3. Got it, just setup the same system property on the application server the app is deployed to.

    ReplyDelete
  4. There 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