Tutorials
Resources
Forum
Reviews
Communities
Interview
Jobs
Projects
Training
Your
Ad
Here
Silverlight Games
|
Mentor
|
Code Converter
|
Articles
|
Code Factory
|
Computer Jokes
|
Members
|
Peer Appraisal
|
IT Companies
|
Bookmarks
|
Polls
|
Revenue Sharing
|
Lobby
|
Gift Shop
|
Prizes & Awards
My Profile
Sign In
Register
AdSense Revenue
Active Members
Today
Abhisek Panda
(40)
Alwyn
(40)
Nadheera V
(20)
Last 7 Days
Alwyn
(704)
nishithraj
(512)
Gaurav Arora
(494)
more...
Resources
»
Code Snippets
»
XML
»
How to Create new Element ,Text,Attributes into a file
Posted Date: 15 Dec 2008
Resource Type:
Code Snippets
Category:
XML
Author:
Arun Krishnan C.P
Member Level:
Gold
Rating:
Points
: 10
1) For this we have to import "org.w3c.dom"
..........................................
2)Specify a file for storing xml content .ie like .xml
3)we have to parse the current xml document.
4)find the location where we have to add the xml content...
5)Save it properly
.............................................................................
***coding***
.................
Document appointmentDoc = appointmentFactory.newDocumentBuilder().parse("D:/OM/JSP/CalendarClient/appointment.xml"); //parsing the .xml content
//getting the root node.
Element root = appointmentDoc.getDocumentElement();
//Creating new element called Appointment.
Element appoiment = appointmentDoc.createElement("Appointment");
//Creating new element called Title.
Element title = appointmentDoc.createElement("Title");
//Creating new element called Date.
Element date = appointmentDoc.createElement("Date");
//Creating new element called Duration.
Element duration = appointmentDoc.createElement("Duration");
//Creating new element called Attendee.
Element attendee = appointmentDoc.createElement("Attendee");
Text textNode = appointmentDoc.createTextNode("text for title");
title.appendChild(textNode);//adding to the node
Text textNode1 = appointmentDoc.createTextNode("text for Data");
date.appendChild(textNode1););//adding to the node
Text textNode2 = appointmentDoc.createTextNode(("text for duration");
duration.appendChild(textNode2););//adding to the node
Text textNode3 = appointmentDoc.createTextNode("AttendeeData");
attendee.appendChild(textNode3););//adding to the node
appoiment.appendChild(date););//adding to the node to root node
appoiment.appendChild(title); //adding to the node to root node
appoiment.appendChild(duration); //adding to the node to root node
appoiment.appendChild(attendee); //adding to the node to root node
root.appendChild(appoiment);
Node firstNode = (Node) root.getFirstChild();//get the first node and insert before it.
root.insertBefore(appoiment, firstNode);
Responses
No responses found. Be the first to respond and make money from
revenue sharing program
.
Feedbacks
Popular Tags
What are tags ?
Search Tags
Sign In
to add tags.
Xml
.
RootNode
.
Add node
.
Post Feedback
This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must
Sign In
to post a response.
Next Resource:
Building an XML Text Writer document
Previous Resource:
XML parser
Return to Discussion Resource Index
Post New Resource
Category:
XML
Post resources and
earn money
!
More Resources
Building an XML Text Writer document
Recursive TeeNode Comparision
Read XML
Importing XML Into a Recordset
Importing XML Into a Recordset
Validate an XML against Schema
dotNet Slackers
About Us
Contact Us
Privacy Policy
Terms Of Use