Latest Tutorials
|
Questions and Answers
|
Ask Questions?
|
Site Map
Home
Java
Frameworks
Database
Technology
Web Development
Build/Test Tools
Servers
PHP
Home
Answers
Viewqa
XML
how to write in xml?
Login
Question
Ask Questions?
Sudarshan
how to write in xml?
1 Answer(s)
4 years and 4 months ago
Posted in :
XML
View Answers
March 17, 2009 at 2:41 AM
Hi friend,
Code to help in solving the problem :
import java.io.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
public class StoreData{
static public void main(String[] arg) {
try{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
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!");
}
else{
System.out.println("File not found!");
}
}
catch (Exception e){
System.err.println(e);
System.exit(0);
}
}
}
For read more information on xml visit to :
http://www.roseindia.net/xml/dom/
Thanks
Post Answer
Preview:
Related Pages:
XMLA
How to write Java Program
How to write in File in Java
How to write in File in Java
how to write code for this output?
How to write image in Jmagick
How to Write to file in Java?
How to write text on image
how to write in xml? - XML
how to write this program
How to write calculator in J2ME program?
how to write servlet program in eclipse?
how to write store procedure in sql
Write to PDF
how to write java data - XML
How to write to file using FileOutputStream
how to write to file at the end of the line
How to Write To File BufferedWriter in Java
Read Write
how to write file from FileInputStream
How to write file by line in Java
How to write method for UITableView didSelectRowAtIndexPath?
How to write a loop and a while loop
How to write into CSV file in Java
how to write append file in Java
How to write to xml file in Java?
how to write and read text for javaME
how to write this program? - Java Beginners
How to write to file using FileWriter
How to write javascripts - JSP-Servlet
how to write the program - Java Beginners
How to write a simple java applet
in string how will write the return statement..........?
How to write javascripts - JSP-Servlet
write data to plist
How To Write the FORM Tag Correctly for Uploading Files?
how to write a query for adding records in database
how to write a english dictionary project in java
Write String in Word document
Write data in doc file
how to read and write an xml file using java
how to write a program to search a record using mvc2
How to write in Binary file in Java programming language
How to write a search functionality using javascript/jquery
Read and write file
how to write to file from string in Java
how to read and write xml files in javascript
How to write file text In New Line
how to write to file primitive type double
How to write the code for date in swings - Struts
Latest
Frameworks
Category
Google Ranking Update for Spammy Queries
Google Penguin Algorithm update issues and How to Recover
change database values when click next button on jsp page
Java
Creating Array in PHP
for-each loop in java
Iterator in java
Java Array declaration
What is Virtual Appliance?
Creating multiple Threads
Hibernate
Struts 1.x
Struts 2
JSF
JavaFX
Ajax
Spring 2.5
Spring 3
DOJO
iBatis
Flex 3
Flex 4
Hibernate Framework
( 1057 )
Struts Framework
( 836 )
Spring Framework
( 567 )
XML
( 196 )
Ajax
( 528 )
JavaScript
( 109 )
Java
( 1806 )
Web Services
( 71 )
Database
( 145 )
Technology
( 90 )
Web Development
( 503 )
PHP
( 406 )