Home Answers Viewqa XML Create XML

 
 


Sumanta
Create XML
1 Answer(s)      4 years and 10 months ago
Posted in : XML

View Answers

August 6, 2008 at 4:15 PM


Hi friend,


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

public class CreateXmlFile {
public static void main(String[] args) throws Exception {
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter number to add elements in your XML file: ");
String str = buff.readLine();
int no = Integer.parseInt(str);
System.out.print("Enter root: ");
String root = buff.readLine();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = dbf.newDocumentBuilder();
Document document = documentBuilder.newDocument();
Element rootElement = document.createElement(root);
document.appendChild(rootElement);
for (int i = 1; i <= no; i++){
System.out.print("Enter the element: ");
String element = buff.readLine();
System.out.print("Enter the data: ");
String data = buff.readLine();
Element em = document.createElement(element);
em.appendChild(document.createTextNode(data));
rootElement.appendChild(em);
}
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(System.out);
transformer.transform(source, result);
}
}


--------------------------------------------------------------------------


Read for more information.

http://www.roseindia.net/xml/dom/

Thanks.









Related Pages:
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
Create XML - XML
Create XML   Hi, Can you please provide java code,that will create xxx.XML file where all the attributes and values of those attributes... elements in your XML file: "); String str = buff.readLine(); int
XML
XML  create flat file with 20 records. Read the records using xml parser and show required details
How to create XML file - XML
How to create XML file  Creating a XML file, need an example. Thanks!!  To create XML file you need plain text editor like note pad. After... language has many API's to create xml file from program.Here is the code example
xml
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
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
how to create a xml page
how to create a xml page  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <
create a xml from sql server 2005 - XML
create a xml from sql server 2005  hello Dear, i want to know how we create a xml file which retrieve data from Sql server 2005 using java. i... with the name as 'student' i want to create a xml file from the table values which
How to create XML from Swings
How to create XML from Swings  How to create XML using Swings. I have a Swing GUI and capturing all data from it.When i click on submit, an xml... components and display it in xml file. import java.io.*; import java.util.*; import
how to create xml schema from xml doc using java
how to create xml schema from xml doc using java  i want to create xml schema from xml document programatically using java... am using Netbeans IDE... need to create the xml schema for that document and send both xml doc ans schema
Create - XML File (Document)
Create - XML File (Document)       In this section, you will  learn to create a XML document using the DOM APIs. This XML document uses  1.0 version  and UTF-8
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
create the SQL tables from an XML schema
create the SQL tables from an XML schema  I'm using Eclipse, Please let me know if anyone developped an application that would automatically create the SQL tables from an XML schema
How to create one xml file from existing xml file's body?
How to create one xml file from existing xml file's body?  Hi, i'm working with content optimization system.I want to know how we can take all data from an xml doc's body to develope another xml with that content.I'm using JDOm
What is XML?
and create well formatted XML document. What is XML Document? Some facts about XML...What is XML? In the first section of XML tutorials we will learn the basics of XML and then write our first xml document. After completing this section
xml developing - XML
xml developing  I want to develop XML document with following DTD file with XML format. I have also XSL file as a externatl file to represent my xml in browser. my problem is i want to create AUTO unique ID & checksum for each
xml developing - XML
xml developing  I want to develop XML document with following DTD file with XML format. I have also XSL file as a externatl file to represent my xml in browser. my problem is i want to create AUTO unique ID & checksum for each
how to write in xml? - XML
Source source = new DOMSource(doc); // Create File to view your xml...how to write in xml?  can anybody give the code how to write in xml...(new InputStreamReader(System.in)); System.out.print("Enter XML file name
how to create an xml file in following clear format
how to create an xml file in following clear format  anyone please help me out to create this file,,. <Tasks> <Taskid>1 <Taskname>Coding <Project>CeMIC <Date>
Java Swing Create XML file
Java Swing Create XML file In this tutorial, you will learn how to create XML... and fetch all the data from textfields and create an xml file with proper... swing components and display it in xml file. We have created textfields
how to create 3d chart in dojox charting - XML
how to create 3d chart in dojox charting  Please provide some example for 3d charting in dojox chart
XML and Velocity
XML and Velocity  How to create xml file using velocity template engine
java and xml problem - XML
java and xml problem  hi, i need to write a java program that generates an xml file as follows: aaa vvv... XML file: "); //String str = bf.readLine(); int no = Integer.parseInt("1
creating document in XML - XML
creating document in XML  Create an XML document for catalogue of Computer Science Book in a Library.   Hi friend...)); System.out.print("Enter number to add elements in your XML file: "); String
Create XML File using Servlet
Create XML File using Servlet       In this section, you will learn how to create xml... XML file with its version and encoding and display a message 'Xml File Created
java - XML
you get the data3. And in the servlet class you can use the DOM api to create xml file//Create blank DOM DocumentDocument doc = docBuilder.newDocument();//create... it to the xml treedoc.appendChild(root);For more information please visit http
Advantages of XML
Advantages of XML   hello, what are the advantage of XML?   Hii, These are the some advantage of xml 1.It is as easy as HTML. 2.XML... application which is capable of processing XML irrespective of the platform
XML Parsers
XML Parsers       XML parser is used to read, update, create and manipulate an XML document. Parsing XML Documents To manipulate an XML document, XML parser is needed. The parser
creating index for xml files - XML
creating index for xml files  I would like to create an index file for xml files which exist in some directory. Say, my xml file is like below: smith 23 USA john 25 USA ... ... All xml files in the directory have
java code to create xml document from DOM object
java code to create xml document from DOM object  Hey! After knowing the way we can create DOM objects and add elements to it-> then displaying it on the console ;is there a way I can output the same in xml document
web.xml - XML
web.xml  Can you please help me to create web.xml I tried to create like this in editplus.. and enter ctrl + B It shows some error.. ---- The XML page cannot be displayed Cannot view XML input using style sheet. Please
java program to create xml file with append data in well-formed
java program to create xml file with append data in well-formed   Sorry sir your given xml append data program is not well-formed. I'll make you more clear what I want. If this is my xml file Tom Cruise 45 Now when I append
Creation of xml
and to create a xml file containing all those datas...My database datas are in key... of query select * from tablename where appid="+12345+". An xml file should be generated ...My xml file should in this format XXXX YYYY
creating tables as an xml document - XML
creating tables as an xml document  Create a table of a medal tally of the Olympic Games as an XML document. The table must have the name..."); // create string from xml tree StringWriter sw = new StringWriter
XML and JavaScript
JavaScript and XML In this section we will see how JavaScript and XML... libraries to fetch the server data. Developer can use these XML data or JSON data retrieved from the server. Here XML plays important role data transfer
Uses of XML
use Flex to create the charts and then use the XML file to feed the data...Uses of XML In this section we are discussing the importance of XML and see the uses of XML. The full form of XML is Extensible Markup Language. XML
XML Tutorial
XML Tutorial XML Tutorial: XML stands for EXtensible Markup Language. In our XML tutorial you will learn what XML is and the difference between XML and HTML. You will also learn how to start using XML in your applications
xml - Servlet Interview Questions
Java servlet xml request  How to create a java servlet xml request
XML Schema
(XSD). In this section, you will learn how to read and create XML Schemas, why...XML Schema           Introduction to XML Schema XML Schema is a W3C Standard
XML and swings - Java Beginners
XML and swings  I have an xml file where all the contents that should be present in the tabbed pane are there. i would like to know how to parse the xml such that, whenever it reads the component type as label, it should create
XML remove tags
XML remove tags  when i remove a tag from xml, it create blank spaces or next line. how i protect it to updae in my xml
xml file creation in java
xml file creation in java  how to create xml file in java so...; Please visit the following links: http://www.roseindia.net/tutorial/java/xml/texttoXML.html http://www.roseindia.net/xml/dom/CreatXMLFile.shtml   
Why XML?, Why XML is used for?
using database and flat files are difficult. XML is also used to create...Why XML? In this section we will understand the importance of XML and see Why XML is so important these days. We will also see the different usages of XML
Create XML file from flat file and data insert into database
Create XML file from flat file and data insert into database... have developed an application to create xml file from flat file and data...). Create a file "FlatFileXml.java"  used to create an XML and data
Java Generate XML Example
Java Generate XML Example To Create a XML in Java using Dom follow the Steps... rootElement.appendChild(ChildElement); 7. Create the output formate // Creating XML output... = dbFactory.newDocumentBuilder(); 3. Create a document object from documentBuilder // Create
Hello World XML
.style1 { background-color: #BFDFFF; } Hello World XML To begin working with XML, you need to learn how to create xml file and how...: In Mozilla: In steps above, you learned how to create xml file and view
Java get XML File
the XML file. For this, you need to create a XML file. Here is the employee.xml file: <?xml version="1.0"?> <company>... Java get XML File     
XML,XML Tutorials,Online XML Tutorial,XML Help Tutorials
parsing of xml documents. Here the Document BuilderFactory is used to create new... XML Tutorials       Transforming XML with SAX Filters This Example shows you the way to Transform XML
Introduction to XML Schema
Introduction to XML Schema       In this tutorial you will learn how to read and create XML Schemas, why XML Schemas are more powerful than DTDs, and how to use them in your

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.