Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
chaitanya sai
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic