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



Home Answers Viewqa XML How to create XML file

Have Programming Question? Ask it here!
 
 
 


neelam
How to create XML file
2 Answer(s)      6 years and 6 months ago
Posted in : XML


Creating a XML file, need an example. Thanks!!


Advertisement
View Answers

February 19, 2008 at 2:19 PM


To create XML file you need plain text editor like note pad. After creating your file save it with .xml extension.


February 22, 2008 at 10:29 PM


Hi,

Java programming language has many API's to create xml file from program.

Here is the code example:

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

public class TestDOM {
public TestDOM() { }
public String doit()
throws javax.xml.parsers.ParserConfigurationException,
javax.xml.transform.TransformerException,
javax.xml.transform.TransformerConfigurationException{

DocumentBuilderFactory factory
= DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
DOMImplementation impl = builder.getDOMImplementation();

Document doc = impl.createDocument(null,null,null);
Element e1 = doc.createElement("howto");
doc.appendChild(e1);

Element e2 = doc.createElement("java");
e1.appendChild(e2);

e2.setAttribute("url","http://www.google.com";);


// transform the Document into a String
DOMSource domSource = new DOMSource(doc);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
//transformer.setOutputProperty
(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");
transformer.setOutputProperty
("{http://xml.apache.org/xslt}indent-amount";, "4");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
java.io.StringWriter sw = new java.io.StringWriter();
StreamResult sr = new StreamResult(sw);
transformer.transform(domSource, sr);
String xml = sw.toString();
return xml;
}

public static void main(String args[])
throws javax.xml.parsers.ParserConfigurationException,
javax.xml.transform.TransformerException,
javax.xml.transform.TransformerConfigurationException{
System.out.println(new TestDOM().doit());

}
}

Thanks


Related Tutorials/Questions & Answers:
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 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
Advertisements
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 prepare XML file?
How to prepare XML file?  Hi, I want to prepare XML File, can you tell me how should I do it? Thanks.   Hello, Following links can help you create an XML file.. Create XML File using Servlet How to generate
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
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"> <
how to read this xml file - XML
how to read this xml file  i want to read this xml file using java... read i have tried lot more , but i am not able to read this xml file...[])throws Exception { File f=new File("C:/data.xml"); DocumentBuilderFactory
How to create XML from Swings
How to create XML from Swings  How to create XML using Swings. I have... components and display it in xml file. import java.io.*; import java.util.*; import...(); createXmlFile(doc,value1,value2,value3,value4); System.out.println("Xml File Created
How to write to xml file in Java?
How to write to xml file in Java?  Hi Friends, Can anyone help me how to write in xml file in Java programming. Please fill free to give example... offers the opportunity to create XML file. For more details visit link text
How to convert XML file to database ?
How to convert XML file to database ?  How to convert XML file to database
how to create ipa file
how to create ipa file  Hi, How to .ipa file? Thanks   Hi, Please check the thread Resources have been modified iPhone. Thanks
how to convert .xml file to csv file
how to convert .xml file to csv file  how to convert .xml file to csv file
How to create a jar file
How to create a jar file  Hello!!!! I have a project which has... a single executable jar of it... so pls tell me how it will b possible for me???   The given code creates a jar file using java. import java.io.*; import
how to seach a keyword in a xml file - XML
how to seach a keyword in a xml file  i have a xml file. i wanted to read and store all the tag values. i have a html form in which when i enter some keyword say "a" then it has to display the tag values starting with a letter
how to modify content of XML file
how to modify content of XML file  hi, I want to modify content of a xml file.There are two tags of similar name say <ContentName>C:\Myinfo... to xml file to replace "XYZ".Every time with the content of text box the file should
What is XML?
and create well formatted XML document. What is XML Document? Some facts about XML: XML file is simple text file with .xml extension. XML file is used... is simple example of XML file: <Invoice>    <to>ABC
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
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     
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
how to convert text file to xml file in java. - XML
how to convert text file to xml file in java.  Hi all, I m having some problem. Problem is I want to convert a text file which is having the no of record(i.e no of different line of information)to a xml file through java
How read xml file value in dojox chart - XML
How read xml file value in dojox chart  How to read the xml file value in dojox chart
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 - XML File (Document)
Create - XML File (Document)       In this section, you will  learn to create a XML... to be added in the generated xml file. It takes the root name at the console and passes
How to Split a large XML file using java?
How to Split a large XML file using java?  How can we split a 500MB Xml file?I know how to split xml file after reading the entire document in a file.Here we cannot load the entire file as it is a large file
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
How to build .XML file, please provide an example.
How to build .XML file, please provide an example.  Hello, I want to know how to build .XML file. If you can provide an example, that would be great... Thanks
how to read and write an xml file using java
how to read and write an xml file using java  Hi Can anyone help me how to read and write an xml file which has CData using java
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
How To Create a New File
How To Create a New File In this section we will discuss about how to create... which will demonstrate you about how to create a new file in Java... store String, characters, numbers etc. In Java to create a File for storing
how to create an excel file using java
how to create an excel file using java  how to create an excel file using java
how to store data in XML file - JSP-Servlet
how to store data in XML file  hi i have to store the data for example user id and password in a xml file the input userid and password will be coming from jsp middle ware servlet how to do that?   Hi friend
How to generate xml file using xpath
How to generate xml file using xpath  Hi, I have a requirement... to make a xml using that,. It would be great is you can help me out with how to make a xml using xpath. Thanks in Advance, Sanjay   Hi Friend, Please
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
how to edit xml file which is currently running in web server - XML
how to edit xml file which is currently running in web server  Hello, I want to add new element in xml file which is currently running in my web server apache tomcat.I can add and modify xml file by giving Path like that "E
how to create pdf file using java and itextjar
how to create pdf file using java and itextjar  How to create pdf file having paragraphs and alignments done using java and itextjar 5.10 version.? hope i get quick response
how to create pdf file using java and itextjar
how to create pdf file using java and itextjar  How to create pdf file having paragraphs and alignments done using java and itextjar 5.10 version.? hope i get quick response
how to create a php script to download file
how to create a php script to download file  php script to download file
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
How to create a .mdf file from script (.sql)
How to create a .mdf file from script (.sql)  Hi, I have a sql database in 2008 server. now i want it to convert to 2005. so i script it. just help me to create a .mdf file back from the script
how can create a jar file - Java Beginners
how can create a jar file  plz any one help me which file can i create the jar file plz give exact command  Hi The basic format... that you want to create a JAR file. * The f option indicates that you want
How to create a jar file with database connection
How to create a jar file with database connection  Hello Everyone... access & i want to create a jar file of it... I have tried with manifest file but its not working pls help me.....   The given code creates a jar
How to create file from input values in Jframe ?
How to create file from input values in Jframe ?  hi i m doing my project using java desktop application in netbeans.i designed a form to get... to take these details and make a file that can be appended each time.how
How to create pdf file in struts2.
How to create pdf file in struts2. In this example, you will see the how to create PDF in struts, and how to write message in generated PDF file in struts2.  For this, we requires a jar file iText.jar. It is used in java
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
How to get xml file form http port using web service
How to get xml file form http port using web service  hi I am suresh... and use the xml data to convert it to java file and store it to DB. But i am struck with getting xml file. How to access xml file in web service? Please Help
how to create own tld and use it in jspx file
how to create own tld and use it in jspx file  I wanted to add fmt as own tag and internationalize add.title=Add. please help me solve the problem. <!-- Document : add Created on : Mar 4, 2012, 7:00:38 PM
how to create own tld and use it in jspx file
how to create own tld and use it in jspx file  I wanted to add fmt as own tag and internationalize add.title=Add. please help me solve the problem. <!-- Document : add Created on : Mar 4, 2012, 7:00:38 PM
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 convert excel file int xml format in java
How to convert excel file int xml format in java  How to read excel file(xls) which is stored in any directory(D://) and convert it into xml format in java and place in any directory(E://).Can any body provide the code
Advertisements
 

 

 

DMCA.com