Home Answers Viewqa XML How to create XML file

 
 


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

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

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 Pages:
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
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 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
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
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 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
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 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 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
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
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
xml file creation in java
xml file creation in java  how to create xml file in java so that input should not be given from keyboard. and that file should be stored.   Please visit the following links: http://www.roseindia.net/tutorial/java/xml
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 configuration file - JDBC
to create a xml file. Please help me out. Thank you  Hi Friend, Try...xml configuration file  Hi, Could you please tell me how to write a xml configuration file . We have mysql database in some other system. I have
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 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
XML
XML  create flat file with 20 records. Read the records using xml parser and show required details
xml
xml  how can i remove white space and next line when i copy stream to xml file
Sorting Xml file - XML
Sorting Xml file  I have an xml file like this: Smith USA... sort my xml file. Here is my xslt..., my ouput file will be like this: Amy AUC Bob USA John UK
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
Storing properties in XML file
Storing properties in XML file       This Example shows you how Store properties in a new XML File. JAXP (Java API for XML Processing) is an interface which provides parsing
XML and Velocity
XML and Velocity  How to create xml file using velocity template engine
how to convert .xml file to csv file
how to convert .xml file to csv file  how to convert .xml file to csv file
xml
xml  how to creatte html file and validate using java and finally i need get web.xml 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
create
create  how to create an excel file using java
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
downloading created xml file - Java Beginners
need to create an xml file and when a button is clicked it has to prompt me for saving the xml file so i created xml file successfully and whats the problem... how can i make that to save as xml file
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
executio of xml file
executio of xml file  how to execute xml file , on web browser
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
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... output format for xml file XMLSerializer fileSerializer = new XMLSerializer
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
xml  how to match to xml file?can you give example with java code
Loading properties from a XML file
Loading properties from a XML file       This Example shows you how to Load properties from a XML file. JAXP (Java API for XML Processing) is an interface which provides parsing
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
write xml file with jsp useBean - JSP-Servlet
write xml file with jsp useBean  how to write into xml files with jsp... an org.w3c.dom.Document from XML. Save the xml file at bin file of C:\apache-tomat-5.5.23\bin... allows our application to obtain a Java XML parser. DocumentBuilderFactory
Reading XML from a File
Reading XML from a File       This Example shows you how to Load Properties from the XML file via... to create new DOM parsers. Some of the methods used for reading XML from a 
Getting next Tag in the XML File
Getting next Tag in the XML File       This Example shows you how to get the next Tag from the XML File. JAXP (Java API for XML Processing) is an interface which provides parsing
how to parse xml in j2me tutorial
how to parse xml in j2me tutorial   i want to parse xml file in j2me wireless toolkit.i saw ur examples & source code for parsing xml file... it is running so can anyone pls tell me how to create a localhost easily step by step
Hello World XML
To begin working with XML, you need to learn how to create xml file and how to structure it. This tutorial explains creating xml and how to use css on it. You...: In Mozilla: In steps above, you learned how to create xml file and view
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... the same structure. It would be like 100 to 200 xml files and each xml file has
Run XML file
Run XML file  Hi.. How do I execute or run an XML file? please tell me about that Thanks
xml - XML
xml  hi convert xml document to xml string.i am using below code...(); //InputStream inputStream = new FileInputStream(new File(xmlData)); InputStream inputStream = new FileInputStream(new File
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
JDOM Element Example, How to get text of element of xml file.
JDOM Element Example, How to get text of element of xml file. In this tutorial, we will see how to get text value of an element from xml file by using JDOM toolkit. JDOM is a library used for manipulating xml file
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

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.