java - Unmarshal a modified xml file -


in java project need unmarshal xml file in order list of objects.

the unmarshalling works fine problem encontourned when content of file modified. in fact in project can add new contents file clicking on "addbuton" when want unmarshal time same file (after modification) old list of objects without last elements (i have added file).

i verified physical xml file on disk , found last content added. noticed way last list of objects close appli , reopen again, unsuitable.

here piece of code:

//classe1.java  file inifile = new file(proprietesperle.getrepref() + "referential.xml");  fileinputstream fs = = new fileinputstream(inifile);  ref = referentiel.unmarshal(fs);      treemap map = referentielutil.getapplication( ref );  ...   //classe2.java  treemap map = new treemap();  list         listpl = app.getpl(); //this list unmarshalled xml file  listiterator itpl    = listpl.listiterator();  while (itpl.hasnext())  {     pl pl = (pl)itpl.next();     map.put(pl.getcode(), pl);  }  return map;  ... 

thank igor response

in fact select app combobox, it's type "application" , variable stocked in session. use this:  session.setattribute("selectedapplication",selectedappli);  treemap mapp = referentielutil.getpl(selectedappli.getapp());  //class referentielutil.java public static treemap getpl(application app) {     logger.debug("getpl");     logger.debug("passe 10");     treemap map = new treemap();      list  listpl = app.getpl();     listiterator itpl    = listpl.listiterator();     while (itpl.hasnext())     {         pl pl = (pl)itpl.next();          map.put(pl.getcode(), pl);     }     return map; }  inside referentiel.unmarshal, find code this:   public void unmarshal(unmarshaller u)     throws unmarshalexception {      xmlscanner xs = u.scanner();     xs.takestart("application");     while (xs.atattribute()) {         string = xs.takeattributename();         throw new invalidattributeexception(an);     }     if (xs.atstart("code")) {         xs.takestart("code");         string s;         if (xs.atchars(xmlscanner.ws_collapse)) {             s = xs.takechars(xmlscanner.ws_collapse);         } else {             s = "";         }         try {             _code = string.valueof(s);         } catch (exception x) {             throw new conversionexception("code", x);         }         xs.takeend("code");     }     if (xs.atstart("libelle")) {         xs.takestart("libelle");         string s;         if (xs.atchars(xmlscanner.ws_collapse)) {             s = xs.takechars(xmlscanner.ws_collapse);         } else {             s = "";         }         try {             _libelle = string.valueof(s);         } catch (exception x) {             throw new conversionexception("libelle", x);         }         xs.takeend("libelle");     }     _typeapplication = ((typeapplication) u.unmarshal());     if (xs.atstart("entite")) {         xs.takestart("entite");         string s;         if (xs.atchars(xmlscanner.ws_collapse)) {             s = xs.takechars(xmlscanner.ws_collapse);         } else {             s = "";         }         try {             _entite = string.valueof(s);         } catch (exception x) {             throw new conversionexception("entite", x);         }         xs.takeend("entite");     }     {         list l = predicatedlists.create(this, pred_pl, new arraylist());         while (xs.atstart("pl")) {             l.add(((pl) u.unmarshal())); // problem here : unmarshal() dont gives last element --------------         }         _pl = predicatedlists.createinvalidating(this, pred_pl, l);     }     xs.takeend("application");    }  noticed in (while loop) dont last element pl want add list "l"  please have idea? 

yep, really, looks don't close/flush outputstream object. try that, should help.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -