aspose file tools*
The moose likes XML and Related Technologies and the fly likes Need Parser program to write elements into xml file..! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Need Parser program to write elements into xml file..!" Watch "Need Parser program to write elements into xml file..!" New topic
Author

Need Parser program to write elements into xml file..!

chaitanya sai
Greenhorn

Joined: May 25, 2006
Posts: 2
Hi All,

I have one xml file like:
<EMPS>
<EMP>
<NAME>Chaitanya</NAME>
<ENO>E001</ENO>
<SEX>M</SEX>
</EMP>
</EMPS>

and my requirement is...

by using any java parser code like DOM or SAX..i have to add one more
<EMP></EMP> entry in xml file...for ex:

</EMP>
<NAME>Krishna</NAME>
<ENO>E002</ENO>
<SEX>M</SEX>
</EMP>

Is there any way to add entry into xml file by using parser program?
(because DOM and SAX provides ways to reading a xml file...)

Please provide me the valuable suggestions to do this task.

i will be so greatful to u if u get me java code...

waiting for ur valuable response..

Thanks in advance.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39541
    
  27
Hello chaitanya-

Welcome to JavaRanch.

On your way in you may have missed that JavaRanch has a policy on display names, and yours does not comply with it; specifically, a first name and a last name are required. Please adjust it accordingly, which you can do right here. Thanks for your prompt attention to this matter.

As to your question, "parsing" refers to reading XML, not generating it. SAX won't help you much with modifying XML, but using DOM this is easily possible. Here is an example program for reading an XML file and creating a DOM Document object, through which you can access the XML elements, add new ones, and save the result to a different file.


Ping & DNS - updated with new look and Ping home screen widget
 
jQuery in Action, 2nd edition
 
subject: Need Parser program to write elements into xml file..!
 
Similar Threads
Formating XML document.
Problem with parsing I need to insert...
Error while updating login-config.xml
xml experts help me SAX Parser in xml
onetomany - hibernateTemplate