java - How does StAX handle XML modifications -
modifying xml files stax possible. trying understand -
--> possible stax update xml documents , when encounters event. if so, there no huge memory footprint great .
example - if reading customers.xml file , need change state information each customer statename statecode. when encounter content -
<state>california</state>
want change <state>ca</state>
so stax can modification source file happen after reading <state>california</state>
, only after parser goes ahead next customer record. when second customers record read first customers state updated in xml state code.
or
--> handle updates temporarily keeping track of changes made , updates whole document in single go after parsing entire document. in case guess there huge memory footprint if there many changes larges documents (say 10gb xml file).
example continued - when second customer processed stax knows state field first customer needs updated defers until customers records read. can use in-memory mechanism keep track of needs updated in xml.
you cannot change xml files in-place stax, can read file in, write file , apply changes on fly. modified stax events (including changes) written target file (except internal buffering purposes).
so size of xml file or number of changes doesn't matter.
if changes depend on other parts in xml becomes more difficult. can process xml file in 2 passes. pass 1 collecting necessary information changes , pass 2 applying changes information gathered in pass 1. or can use totally different approach xml databases (e.g. basex) , apply changes xquery.
Comments
Post a Comment