You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xmlbeans.apache.org by "Steve Single (JIRA)" <xm...@xml.apache.org> on 2012/08/02 17:36:02 UTC

[jira] [Commented] (XMLBEANS-386) XmlObject.Factory.parse throws "Unexpected element: CDATA"

    [ https://issues.apache.org/jira/browse/XMLBEANS-386?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13427391#comment-13427391 ] 

Steve Single commented on XMLBEANS-386:
---------------------------------------

I had the same problem and found a solution.

My code to load the data xml files was:

String filename = "myfile.xml";

XmlObject xmlObj = XmlBeans.getContextTypeLoader().parse(filename, VenuesRequestDocument.type, null);

And what worked was :

XmlObject xmlObj = XmlBeans.getContextTypeLoader().parse(new FileInputStream(filename), VenuesRequestDocument.type, null);

It appears that the first version with a String in the place of the filename instead of a FileInputStream is treated as the actual XML instead of the filename of the actual XML. Hence the CDATA message, because a filename is not valid XML, of course. Doh!
                
> XmlObject.Factory.parse throws "Unexpected element: CDATA"
> ----------------------------------------------------------
>
>                 Key: XMLBEANS-386
>                 URL: https://issues.apache.org/jira/browse/XMLBEANS-386
>             Project: XMLBeans
>          Issue Type: Bug
>          Components: XmlObject
>    Affects Versions: Version 2.4 
>         Environment: Java 1.5.0_11, Windows Server 2003, XmlBeans 2.4.0
>            Reporter: Aleksei Kazantsev
>            Priority: Minor
>         Attachments: __d3configserver.xml
>
>
> Attached XML fails to be parsed.
> Java code to reproduce the problem:
>           XmlObject xml = XmlObject.Factory.parse(new File("d:/__d3configserver.xml"));
> Throws:
> org.apache.xmlbeans.XmlException: d:\__d3configserver.xml:457:1: error: Unexpected element: CDATA
> 	at org.apache.xmlbeans.impl.store.Locale$SaxLoader.load(Locale.java:3486)
> 	at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1276)
> 	at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1263)
> 	at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:345)
> 	at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:252)
> 	at org.apache.xmlbeans.XmlObject$Factory.parse(XmlObject.java:639)
> 	at com.agfa.apomedia.translation.UtilsTest.testGetTranslatedFile(UtilsTest.java:122)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:585)
> 	at junit.framework.TestCase.runTest(TestCase.java:154)
> 	at org.jmock.integration.junit3.VerifyingTestCase.runBare(VerifyingTestCase.java:37)
> 	at junit.framework.TestResult$1.protect(TestResult.java:106)
> 	at junit.framework.TestResult.runProtected(TestResult.java:124)
> 	at junit.framework.TestResult.run(TestResult.java:109)
> 	at junit.framework.TestCase.run(TestCase.java:118)
> 	at junit.framework.TestSuite.runTest(TestSuite.java:208)
> 	at junit.framework.TestSuite.run(TestSuite.java:203)
> 	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
> 	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
> Caused by: org.xml.sax.SAXParseException: Unexpected element: CDATA
> 	at org.apache.xmlbeans.impl.piccolo.xml.Piccolo.reportFatalError(Piccolo.java:1038)
> 	at org.apache.xmlbeans.impl.piccolo.xml.Piccolo.parse(Piccolo.java:723)
> 	at org.apache.xmlbeans.impl.store.Locale$SaxLoader.load(Locale.java:3454)
> 	... 24 more

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org