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
Post a Comment