JAXB Binder.updateXml(objectTobeUpdated) fails when called twice -


i have existing xml, im using jaxb update it. following code fails: there bugs raised on issue, couldnt information fix. can kindly on how resolve issue.

    package la.te.st;      import javax.xml.bind.annotation.xmlattribute;     import javax.xml.bind.annotation.xmlelement;     import javax.xml.bind.annotation.xmlrootelement;      @xmlrootelement     public class student{         string name;        int age;        int id;         public string getname(){           return name;        }         @xmlelement        public void setname(string name){           this.name = name;        }         public int getage(){           return age;        }         @xmlelement        public void setage(int age){           this.age = age;        }         public int getid(){           return id;        }         @xmlattribute        public void setid(int id){           this.id = id;        }         @override         public string tostring() {             return this.name + " age:" + this.age + " id:" + this.id;         }     }    /**************************************/  package la.te.st;   import javax.xml.bind.jaxbcontext; import javax.xml.bind.marshaller; import javax.xml.bind.binder; import javax.xml.parsers.documentbuilder; import javax.xml.parsers.documentbuilderfactory; import javax.xml.transform.transformer; import javax.xml.transform.transformerfactory; import javax.xml.transform.dom.domsource; import javax.xml.transform.stream.streamresult;  import org.w3c.dom.document; import org.w3c.dom.node;  public class binderdemo {    public static void main(string[] args) {        try {          // need blank document store final xml output          documentbuilderfactory dbf = documentbuilderfactory.newinstance();          documentbuilder docbuilder = dbf.newdocumentbuilder();          document document = docbuilder.parse("student.xml");           // create jaxbcontext used create binder          jaxbcontext jc = jaxbcontext.newinstance(student.class);           binder<node> binder = jc.createbinder();           // set output formatted 1          binder.setproperty(marshaller.jaxb_formatted_output, true);           // xml node document          node xmlnode = document.getdocumentelement();           // returns updated jaxb object          student st = (student)binder.updatejaxb(xmlnode);           system.out.println(st);          // set age , name          st.setage(11);          st.setname("sania");           system.out.println(st);          // update xml node new data          xmlnode = binder.updatexml(st);           st.setage(12);          st.setname("sania");           system.out.println(st);           xmlnode = binder.updatexml(st);           // set node value document          document.setnodevalue(xmlnode.getnodevalue());           // print edited object on stdout          transformerfactory tf = transformerfactory.newinstance();          transformer t = tf.newtransformer();          t.transform(new domsource(document), new streamresult(system.out));        }catch(exception ex) {          ex.printstacktrace();       }    } }   /*****************************/  student.xml file :  <?xml version="1.0" encoding="utf-8" standalone="no"?> <student id="10">    <age>10</age>    <name>zara ali</name> </student> 


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -