This Example shows you how to adds an attribute in a DOM document. JAXP (Java API for XML Processing) is an interface which provides parsing of xml documents. Here the Document BuilderFactory is used to create new DOM parsers. There are some of the methods used in code given below for adding attribute:-
getDocumentElement():- allows direct access to the root node of the document.
root.getAttribute("Id"):-allows to retrieve attributes on Id.
root.setAttribute("Id", "05MC34"):-allows to set o5Mc34 on the Id
Xml code for the program generated is:-
<?xml version="1.0" encoding="UTF-8"?> <Author Type='Bible' Id='Rose-78' Issue='1995'> </Author>
Output of the program:-
Attributes of Id before Adding is: Rose-78 Attributes of Id after Adding is: 05MC34
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.