java - UnmarshalException error -


i'm trying unmarshal dom parsed document can update xml. got following namespace error:

javax.xml.bind.unmarshalexception: unexpected element (uri:"", local:"showing_today"). expected elements <{http://xml.netbeans.org/schema/shows}showing_today> 

here my: package-info.java

@javax.xml.bind.annotation.xmlschema (namespace = "http://xml.netbeans.org/schema/shows", elementformdefault = javax.xml.bind.annotation.xmlnsform.qualified)  package media; 

here xml file i'm trying unmarshal:

  <?xml version="1.0" encoding="utf-8" standalone="yes" ?>   <showing_today xmlns="http://xml.netbeans.org/schema/shows">  <movie_collection>   <title>red</title>    <director>robert schwentke</director>    <year>2010</year>    </movie_collection> 

showingtoday.java

@xmlaccessortype(xmlaccesstype.field) @xmltype(name = "", proporder = {     "moviecollection" }) @xmlrootelement(name = "showing_today") public class showingtoday {      @xmlelement(name = "movie_collection")     protected list<movietype> moviecollection; 

and here unmarshaller code:

documentbuilderfactory dbf = documentbuilderfactory.newinstance(); documentbuilder docbuilder = dbf.newdocumentbuilder(); document domdoc = docbuilder.parse("now_showing.xml"); dbf.setnamespaceaware(true);  jaxbcontext jaxbctx = javax.xml.bind.jaxbcontext.newinstance(showingtoday.class); binder <node> binder = jaxbctx.createbinder(); unmarshaller unmarshaller = jaxbctx.createunmarshaller(); showingtoday shows2 = (showingtoday) binder.unmarshal(domdoc); 

i've looked @ many similar questions, none of solutions helped. suggestions on how can fix it? thank you

you need call setnamespaceaware() before create documentbuilder. setting after you've created parser , built dom have no effect. that's reason why jaxb unable unmarshal root element, missing namespace.

try this:

documentbuilderfactory dbf = documentbuilderfactory.newinstance(); dbf.setnamespaceaware(true); documentbuilder docbuilder = dbf.newdocumentbuilder(); document domdoc = docbuilder.parse("now_showing.xml"); 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -