File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes How to add Attributes to a existing XML File. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to add Attributes to a existing XML File." Watch "How to add Attributes to a existing XML File." New topic

How to add Attributes to a existing XML File.


Joined: Jun 04, 2001
Posts: 4
hi friends,
This is Palash from India says hello to u all.
In between days i am doing on XML & java.
i have some problem...
can u tell me How can i add an Atttribute to my existing
XML file...
i am able to read values from XML file but not able to modify or add.
please reply if possible...
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
hi palash,
am also new in XML.
Okay i guess DOM provides a way to insert an attribute.
So read in ur xml document using a dom parser.
org.w3c.dom.Element interface has a setAttribute()/ setAttributeNode() methods for the same. SO i guess u can add one when u encounter the element of your choice.
I hope Ajit/map/ someone w'd correct me if i'm wrong.
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Cynthia Yao
Ranch Hand

Joined: Nov 06, 2000
Posts: 92
I remember that only XmlDocument can actually write to a output file. here is the api link:
it is in jaxp package, you may need to download the jar file from sun
I agree. Here's the link:
subject: How to add Attributes to a existing XML File.
It's not a secret anymore!