how to write in xml?



Share on Google+Share on Google+

how to write in xml?
1 Answer(s)      8 years ago
Posted in : XML
View Answers

March 17, 2009 at 2:41 AM

Hi friend,

Code to help in solving the problem :

import org.w3c.dom.*;
import org.xml.sax.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;

public class StoreData{
static public void main(String[] arg) {
BufferedReader bf = new BufferedReader(new InputStreamReader(;
System.out.print("Enter XML file name: ");
String xmlFile = bf.readLine();
File file = new File(xmlFile);
if (file.exists()){
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(xmlFile);
// Create transformer
Transformer tFormer = TransformerFactory.newInstance().newTransformer();
// Output Types (text/xml/html)
tFormer.setOutputProperty(OutputKeys.METHOD, "text");
// Write the document to a file
Source source = new DOMSource(doc);
// Create File to view your xml data as vk.txt/vk.doc/vk.xls/vk.shtml/vk.html)
Result result = new StreamResult(new File("vk.txt"));
tFormer.transform(source, result);
System.out.println("File creation successfully!");
System.out.println("File not found!");
catch (Exception e){

For read more information on xml visit to :



Java Spring Hibernate Struts Training were to start with xml, XSD and java write a program that Implement an integrated COM client server to add two visuall studio 2010 Building a Parent Child relationship XML how i connect two page xml question struts cfg file for DispatchAction with mysql db Creating custom output using XMLUnit - MatchTracker duplicates the output data Related to XML Related to XML Reading child of child nodes in xml Reading multiple xml files Spliting Large XML and one by one Moved to Output Folder XMl and Java web services project download xml file from website using java code Download how to create an xml file in following clear format Conditional increment in xslt Conditional increment in xslt Conditional increment in xslt HOW TO STORE MULTIPLE EMPLOYEE DETAILS TO XML FILE USING JSP? xml and servlets xml and servlets Question about parsing XML document with DOM in JAVA. Removal of XML header Converting PHP page with flash to JSP page without flash saving data in xml Doubt about Xstream Converter Reading xml file using dom parser in java with out using getelementby tag name xml dynamically how to change attiribute values in xml XML Schema xml xml sax parser for xml parsing xml using sax xml to html via java i want java code for this xml file...please show me.. SAX Parser for huge XML file xml parsing "opening video data error" in j2me XML to JSP mapview1 mapview searchbar searchbar jsonparsing xmlparsing retrieve multiple attribute values retrieve multiple attribute values


Advertisement null