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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


vasu
creating Xml
3 Answer(s)      6 years and 9 months ago
Posted in : Java Beginners


how we can create a xml file using java Creating XML File is possible in java with this packages. import... this Elemnts to DOcumnet object. Creating XML File is possible


Advertisement
View Answers

February 26, 2008 at 3:07 PM




Creating XML File is possible in java with this packages.

import org.w3c.dom.Document;
import org.w3c.dom.Element;

First try to get the
1.DocumentBuilderFactory object
2.with this Try to get the Document Object
3.With The Created Document Object ,try to add Your Elements by Element Object.
4. Appeng this Elemnts to DOcumnet object.



February 26, 2008 at 3:08 PM




Creating XML File is possible in java with this packages.

import org.w3c.dom.Document;
import org.w3c.dom.Element;

First try to get the
1.DocumentBuilderFactory object
2.with this Try to get the Document Object
3.With The Created Document Object ,try to add Your Elements by Element Object.
4. Appeng this Elemnts to DOcumnet object.



April 16, 2008 at 7:23 PM


Hi friend,

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

public class CountElementExample{
public static void main(String[] args) {
try {
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter File name: ");
String str = buff.readLine();
File file = new File(str);
if(file.exists()){
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// Create the builder and parse the file
Document doc = factory.newDocumentBuilder().parse(str);
System.out.print("Enter element name: ");
String element = buff.readLine();
NodeList nodes = doc.getElementsByTagName(element);
System.out.println("xml Document Contains " + nodes.getLength() + " elements.");
}
else{
System.out.print("File not found!");
}
}
catch (Exception ex) {
System.out.println(ex);
}
}
}

<?xml version = "1.0" ?>
<Employee-Detail>

<Employee>
<Id> E-001</Id>
<Emp_Name>Amardeep</Emp_Name>
<Emp_E-mail>amar@rediffmail.com</Emp_E-mail>
</Employee>

<Employee>
<Id> E-002 </Id>
<Emp_Name>Anjali</Emp_Name>
<Emp_E-mail>anjali@yahoo.com </Emp_E-mail>
</Employee>

<Employee>
<Id> E-003 </Id>
<Emp_Name>Sonu</Emp_Name>
<Emp_E-mail>sonu38@yahoo.com </Emp_E-mail>
</Employee>

<Employee>
<Id> E-004</Id>
<Emp_Name>Sandeep</Emp_Name>
<Emp_E-mail>sonu3@yahoo.com </Emp_E-mail>
</Employee>

<Employee>
<Id>E-005</Id>
<Emp_Name>chandan</Emp_Name>
<Emp_E-mail>ravi@rediffmail.com</Emp_E-mail>
</Employee>

<Employee>
<Id>E-006</Id>
<Emp_Name>suman</Emp_Name>
<Emp_E-mail>suman@rediffmail.com</Emp_E-mail>
</Employee>

</Employee-Detail>


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


Related Tutorials/Questions & Answers:
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
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
Advertisements
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
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...(); DocumentBuilder docBuilder = builderFactory.newDocumentBuilder(); //creating a new
creating Xml - Java Beginners
creating Xml  how we can create a xml file using java Creating XML... object. Creating XML File is possible  Creating XML File is possible... by Element Object.4. Appeng this Elemnts to DOcumnet object.  Creating XML
problem in creating web application using servelet, jsp, jdbc and xml - JSP-Servlet
problem in creating web application using servelet, jsp, jdbc and xml  Using Servlet, JSP, JDBC and XML create a web application for a courrier company to provide online help in tracking the delivery status of items.  
XML
XML  How i remove a tag from xml and update it in my xml
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
XML  create flat file with 20 records. Read the records using xml parser and show required details
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  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
Hello World XML
to structure it. This tutorial explains creating xml and how to use css on it. You can use css to present xml data with styles. Creating XML: 1. Open any text... .style1 { background-color: #BFDFFF; } Hello World XML
XML Syntax Rules
XML Syntax Rules       The syntax  rules  for  XML are very simple and strict. These  are  easy to learn and  use. Because of this, creating software
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
XML - XML
XML XSD validation in java  Can anyone help in writing validation for XML XSD in 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
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 using JAXB. Since we are going to do work with the XML files and using JAXB
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
Creating an Applet
Creating an Applet  Hi, I have get a task regarding Creating an Applet using all Layout Manager, can anyone help me in this regard. I donā??t know how to make and please help me. Thanks.   To answer of your query
 

 

 

DMCA.com