java - Replace default namespace value from large xml -


i have large xml file has default namespace value. how can replace value without loading entire file in memory using java?

<?xml version="1.0" encoding="utf-8" standalone="yes"?> <customer xmlns="http://www.example.org/package">     <id>123</id> </customer> 

should become

<?xml version="1.0" encoding="utf-8" standalone="yes"?> <customer xmlns="http://www.example.org/another">     <id>123</id> </customer> 

there's "hacky" way: stream file (using reader , "utf-8" charset) , string replacement.

the "real" way use sax or preferably stax. can use xmleventreader , xmleventwriter stream through xml , manipulate without ever loading whole thing in memory. when element events wrong namespace, create new element events right namespace , pass them along writer.


Comments

Popular posts from this blog

php - Extract Text from HTTP referer -

Receive udp packets in android gstreamer -

ios - How to Rectify the Relationship Fault in CoreData While parsing RESTKIT? -