How to add multiple node in xml using java -
i want create xml file this:
<record number="001"> <refnum></refnum> <trackref></trackref> <record> </batch>
how can create element record number spaces in between , how give value "001"?
you can use documentbuilder creating xml.
please see sample code below:
documentbuilderfactory dbfactory = documentbuilderfactory.newinstance(); documentbuilder dbuilder = dbfactory.newdocumentbuilder(); document doc = dbuilder.newdocument(); // root element element rootelement = doc.createelement("");
then output result in xml file as shown below :
// write content xml file transformerfactory transformerfactory = transformerfactory.newinstance(); transformer transformer = transformerfactory.newtransformer(); domsource source = new domsource(doc); streamresult result = new streamresult(new file("c:\\test.xml")); transformer.transform(source, result);
Comments
Post a Comment