Share on Google+Share on Google+

1 Answer(s)      8 years ago
Posted in : XML
View Answers

July 16, 2009 at 1:30 PM

Hi Firend,

Try the following code:

import java.io.*;
import java.util.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;

public class ReadXML {
public static void main(String args[]) throws Exception {
FileInputStream input = new FileInputStream("data.xml");
FileOutputStream output = new FileOutputStream("new.xml");
ReadXML xml = new ReadXML();
xml.convert(input, output);
System.out.println("XML File is converted into XML string.");
public void setParameter(Map param) {
Map map = param;
public void convert(InputStream in, OutputStream out)
throws Exception {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transform = tf.newTransformer();

Document doc = builder.newDocument();
Element ele = doc.createElement("Tags");
Element e = doc.createElement("string");

BufferedReader br = new BufferedReader(new InputStreamReader(in));
StringBuffer buffer = new StringBuffer();
String line="";
while ((line = br.readLine()) != null) {
String st=buffer.toString();
Text text = doc.createTextNode(st);
DOMSource source = new DOMSource(doc);
transform.transform((source), new StreamResult(out));
} catch (Exception e) {




Related Tutorials/Questions & Answers:
XML  How i remove a tag from xml and update it in my xml
xml  validate student login using xml for library management system
xml  why the content written in xml is more secure
xml  validate student login using xml for library management system
xml  what is name space,xml scema give an example for each   XML Namespaces provide a method to avoid element name conflicts.They are used for providing uniquely named elements and attributes in an XML document
XML  Hi...... Please tel me about that Aren't XML, SGML, and HTML all the same thing? Thanks
XML  please tell me how i remove one tag out of all similar type of tags in xml
xml  how can i remove white space and next line when i copy stream to xml file
XML  create flat file with 20 records. Read the records using xml parser and show required details
xml  what is xml   Extensible Markup Language (XML... that is both human-readable and machine-readable. It is defined in the XML 1.0... gratis open standards. The design goals of XML emphasize simplicity, generality
XML  Design an XML to maintain book details to do the following: (i) Separate Data (ii) Exchange Data (iii) Store Data (iv) Create new language
xml  Design an XML to maintain book details to do the following: (i) Separate Data (ii) Exchange Data (iii) Store Data (iv) Create new language
XML  What is specific definatio of XML? Tell us about marits and demarits of XML? use of XML? How we can use of XML?  Hi, XML... language much like HTML used to describe data. In XML, tags are not predefined
XML XSD validation in java  Can anyone help in writing validation for XML XSD in Java
XML  How to run XML program?  Hi Friend, Please visit the following links: http://www.roseindia.net/xml/ http://www.roseindia.net/xml/dom/ Hope that it will be helpful for you. Thanks
XML  How to convert database to XML file?   Hi Friend, Do you want to store database data into xml file ? Please clarify this. Thanks
xml - XML
xml  how to match to xml file?can you give example with java code
xml - XML
friend, XPath : It is a language for finding information in an XML document. It is used to navigate through elements and attributes in an XML document. It is a language for selecting nodes from an XML document. It is used
xml - XML
xml  define parser and xml,in jaxp api how to up load parsers... then the program contains syntax errors. XML is defined as an extensible... information,Examples and Tutorials on Xml visit to : http
xml - XML
xml  hi convert xml document to xml string.i am using below code... = stw.toString(); after i am getting xml string result, like Successxxx profile... Friend, Please visit the following link: http://www.roseindia.net/xml/reading
xml - XML
xml  hi convert xml file to xml string in java ,after getting the xml string result and how to load xml string result? this my problem pls help..."); FileOutputStream output = new FileOutputStream("new.xml"); ReadXML xml = new
XML  Write a program using SAX that will count the number of occurrences of each element type in an XML document and display them. The document file...)); System.out.print("Enter XML file name:"); String xmlFile = bf.readLine
Consolidated XML to individual XML - XML
Consolidated XML to individual XML  How to separate the consolidated XML file to separate the individual XML names, when a user import the consolidated XML file
Creating XMl file - XML
Creating XMl file   I went on this page: http://www.roseindia.net/xml/dom/createblankdomdocument.shtml and it shows me how to create an XML file, however there is something I don't understand. I have to create an XML file
xml code - XML
xml code  I Read xml is used to store and transfer data can you explain it with sample code
xml certification dumps - XML
xml certification dumps  hi need information. xml certification purpose dumps
snmp /xml gateway - XML
snmp /xml gateway  hi i would like to develop a snmp management application based on xml for that i need to construct a snmp/xml gateway which translates the xml queries into snmp command and inturn translates the returned
xml_append - XML
xml_append  hi i have a xml file im.xml its contents: asaddasahellojim i have to add more tags to .. pls help me to solve this.. ...://www.roseindia.net/xml/ Thanks
tags in xml - XML
tags in xml  Can I use : (colon )in xml tag? For ex. Is this valid?  Hi Friend, You can use colon(:) in XML tag.But is not valid. Thanks
Create XMl dynamically - XML
Create XMl dynamically  Hi I am retreiving the list from database which i need to display in an XML file with some nodes How can I do
XML with JSP - XML
XML with JSP  Hai all,, I have a doubt..is it possible to submit jsp form data in to xml... i mean after filling the HTML form when i give submit it should save all the content in xml instead of DB. Then i want to fetch all


Advertisement null