reading xml file and parsers in java -


i trying read xml file using fileinputstreamreader class. but, when try read large xml files, problems occur. java class more suitable read large xml files , efficient parsers parse xml files?

i think dom parsing way parse xml files

documentbuilderfactory factory = documentbuilderfactory.newinstance(); documentbuilder docbuilder = factory.newdocumentbuilder(); document doc = docbuilder.parse(yourfile); 

in way start parsing of xml document, can modify nodes , change want change

transformerfactory tf = transformerfactory.newinstance(); transformer transformer = tf.newtransformer(); domsource source = new domsource(yourdoc); streamresult result = new streamresult(yourfile); transformer.setoutputproperty(outputkeys.indent, "yes"); transformer.setoutputproperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer.setoutputproperty(outputkeys.indent, "yes"); transformer.transform(source, result); 

and second parte save changes. "setoutputpropery" method not mandatory, it's used give xml file nice indent.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -