java - XmlBeans error: unexpected element CDATA when parsing String -


i'm having problems parsing xml string using xmlbeans. problem in j2ee application string received external systems, replicated problem in small test project.

the solution found let xmlbeans parse file instead of string, that's not option in j2ee application. plus want know problem because want solve it.

source of test class:

public class testxmlspy {      public static void main(string[] args) throws ioexception {         inputstreamreader reader = new inputstreamreader(new fileinputstream("d:\\temp\\ie734.xml"),"utf-8");         bufferedreader r = new bufferedreader(reader);         string xml = "";         string str;          while ((str = r.readline()) != null) {             xml = xml + str;         }         xml = xml.trim();         system.out.println("ready reading xml");         xmloptions options = new xmloptions();         options.setcharacterencoding("utf-8");          try {             xmlobject xmlobject = xmlobject.factory.parse(new file("d:\\temp\\ie734.xml"), options);             system.out.println("ready parsing file");             xmlobject.factory.parse(xml, options);             system.out.println("ready parsing string");         } catch (xmlexception e) {             // todo auto-generated catch block             e.printstacktrace();         }     }    } 

the xml file validates against xsd's im using. also, parsing file object works fine , gives me parsed xmlobject work with. however, parsing xml-string gives stacktrace below. i've checked string in debugger , don't see wrong @ first sight, not @ row 1 column 1 think sax parser having problem if i'm interpreting error correctly.

debug

stacktrace:

ready reading xml ready parsing file org.apache.xmlbeans.xmlexception: error: unexpected element: cdata     @ org.apache.xmlbeans.impl.store.locale$saxloader.load(locale.java:3511)     @ org.apache.xmlbeans.impl.store.locale.parse(locale.java:713)     @ org.apache.xmlbeans.impl.store.locale.parsetoxmlobject(locale.java:697)     @ org.apache.xmlbeans.impl.store.locale.parsetoxmlobject(locale.java:684)     @ org.apache.xmlbeans.impl.schema.schematypeloaderbase.parse(schematypeloaderbase.java:208)     @ org.apache.xmlbeans.xmlobject$factory.parse(xmlobject.java:658)     @ xmlspy.testxmlspy.main(testxmlspy.java:37) caused by: org.xml.sax.saxparseexception; systemid: file:; linenumber: 1; columnnumber: 1; unexpected element: cdata     @ org.apache.xmlbeans.impl.piccolo.xml.piccolo.reportfatalerror(piccolo.java:1038)     @ org.apache.xmlbeans.impl.piccolo.xml.piccolo.parse(piccolo.java:723)     @ org.apache.xmlbeans.impl.store.locale$saxloader.load(locale.java:3479)     ... 6 more 

this encoding problem, used below code worked me:

        file xmlfile = new file("./data/file.xml");         filedocument filedoc = filedocument.factory.parse(xmlfile); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -