i have update xml document object generated using apache xmlbeans.there 2 ways trying update , save document.
step 1 : parsing document , updating new values , saving parsed document itself.
private boolean updatecontact(contacttype contacts, string contactfilepath, string name) throws exception { contactsdocument contactdoc = contactsdocument.factory.parse(new file(contactfilepath)); contacttype contact = contactdoc.getcontacttype(); contact.setname(name); contactdoc.save(new file(contactfilepath) , xmlutils.getdefaultfilesavingoptions()); }
step 2 : passing updated document type , creating new instance of xml document , saving updated type.
private boolean writecontact(contacttype contacttype, string contactfilepath) throws exception { contactsdocument contactsdoc = contactsdocument.factory.newinstance(); contactsdoc.setcontacttype(contacttype); contactsdoc.save(new file(contactfilepath), xmlutils.getdefaultfilesavingoptions()); }
the step 2 working want know, step 1 work ? , efficient way of doing scenario.
the step 1 works perfect xml default file saving options , not modifies or removes of existing namespaces present in file.
private boolean updatecontact(contacttype contacts, string contactfilepath, string name) throws exception { contactsdocument contactdoc = contactsdocument.factory.parse(new file(contactfilepath)); contacttype contact = contactdoc.getcontacttype(); contact.setname(name); contactdoc.save(new file(contactfilepath) , xmlutils.getdefaultfilesavingoptions()); }
it approach parse file , save changes on top of it, instead of parse , instantiating xml document every updates.
Comments
Post a Comment