Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa XML Create XML

Have Programming Question? Ask it here!
 
 
 


Sumanta
Create XML
1 Answer(s)      6 years ago
Posted in : XML



Advertisement
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 Tutorials/Questions & Answers:
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
Advertisements
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
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
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
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
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 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
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
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
XML  create flat file with 20 records. Read the records using xml parser and show required details
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
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
XML
XML  How i remove a tag from xml and update it in my xml
JAXB Create XML File And Get Data From XML
JAXB Create XML File And Get Data From XML In this section we will read about how to create XML file and how to convert XML file's data to Java Object... : Here we are giving a simple example into which we will first create an XML file
xml
xml  validate student login using xml for library management system
xml
xml  validate student login using xml for library management system
xml
xml  why the content written in xml is more secure
xml
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 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
XML
XML  please tell me how i remove one tag out of all similar type of tags in xml
xml
xml  how can i remove white space and next line when i copy stream to xml file
XML
XML  Hi...... Please tel me about that Aren't XML, SGML, and HTML all the same thing? Thanks
xml
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 - XML
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
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 - XML
XML XSD validation in java  Can anyone help in writing validation for XML XSD in Java
create
create  how to create an excel file using java
XML - XML
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 - XML
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
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  how to match to xml file?can you give example with java code
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  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 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
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
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 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
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
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
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
XML and Velocity
XML and Velocity  How to create xml file using velocity template engine
 

 

 

DMCA.com