hi
i am able to update the xml using below code ;but i when i see the xml there is no indenting and some square blocks r coming in xml;how to remove those blocks and how to achieve indenting;i think these blocks r coming because of spaces in xml;
<?xml version = '1.0'?>
<India>
<IndianPlayer>
<Name>1111111</Name>
<Age>1111111111</Age>
</IndianPlayer><IndianPlayer> <Name>wrw</Name> <Age>rwrwr</Age> </IndianPlayer><IndianPlayer> <Name>55555555555</Name>
<Age>555555555</Age>
</IndianPlayer>
</India>
String fname="name.xml";
DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = fac.newDocumentBuilder();
Document
doc = db.parse(new FileInputStream("name.xml"));
Element root = doc.getDocumentElement();
Element main1 = doc.createElement("IndianPlayer");
Element productnames1 = doc.createElement("Name");
Text product1 = doc.createTextNode(request.getParameter("name1"));
Element price1 = doc.createElement("Age");
Text priceValues1 = doc.createTextNode(request.getParameter("age1"));
productnames1.appendChild(product1);
price1.appendChild(priceValues1);
main1.appendChild(productnames1);
main1.appendChild(price1);
root.appendChild(main1);
saveDocAsFile(doc,fname);
}
catch (ParserConfigurationException e) {
e.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void saveDocAsFile(Document doc, String fname) {
try {
TransformerFactory tfFac = TransformerFactory.newInstance();
// use null trandformation
Transformer tf = tfFac.newTransformer();
tf.setOutputProperty(OutputKeys.INDENT,"yes");
tf.transform(new DOMSource(doc), new StreamResult(fname));
}
/* catch (IOException ioe) {
ioe.printStackTrace();
}*/
catch (TransformerException e) {
e.printStackTrace();
}
[ June 17, 2004: Message edited by: kesava chaitanya ]