//create an element named "link" Element link=doc.createElement("link"); /*create an element of context named "name" context is consided with an element by w3c */ Element linkName=doc.createElement("name"); Text textName=doc.createTextNode(name2); linkName.appendChild(textName); link.appendChild(linkName); doc.getDocumentElement().appendChild(link);//return a root node of document
TransformerFactory tFactory =TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(new java.io.File("links.xml")); transformer.transform(source, result); } catch(Exception e){} } }