Java Modify XML -


i want read xml file in java , update elements in file new values. file > 200mb , performance important, dom model cannot used.

i feel stax parser solution, there no decent literature on using java stax read , write xml same file.

(for reference have been using the java tutorial , this helpful tutorial have far)

i using java 7, there doesn't seem updates xml parsing api since...a long time ago. isn't relevant.

currently have this:

public static string readvaluefromxml(final file xmlfile, final string value) throws filenotfoundexception, xmlstreamexception {     xmleventreader reader = new xmlinputfactory.newfactory().createxmleventreader(new filereader(xmlfile));      string found = "";     boolean read = false;      while (reader.hasnext())     {         xmlevent event = reader.nextevent();         if (event.isstartelement() &&             event.asstartelement().getname().getlocalpart().equals(value))         {             read = true;         }          if (event.ischaracters() && read)         {             found = event.ascharacters().getdata();             break;         }     }      return found; } 

which read xmlfile , return value of selected element. however, have method updatexmlfile(final file xmlfile, final string value) want use in conjunction this.

so question threefold:

  1. is there stax implementation editing xml
  2. will xpath help? can used without converting file document?
  3. (more generally) why doesn't java have better xml api?

there 2 things may want at. first use jaxb bind xml pojos can have way , serialize structure xml when needed.

the second jdbc driver xml, there several available fee, not sure if there open source ones or not. in experience jaxb better choice. if xml file large handle efficiently jaxb think need @ using database replacement xml file.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -