Creating xml using DOM in java -
i trying create xml multiple elements. below code trying.
element root = doc.createelement("root"); doc.appendchild(root); element member = doc.createelement("member"); root.appendchild(member); element name = doc.createelement("name"); name.appendchild(doc.createtextnode("xxx")); member.appendchild(name); element phone = doc.createelement("phone"); phone.appendchild(doc.createtextnode("vvvv")); member.appendchild(phone); element sss = doc.createelement("somethingnew"); root.appendchild(sss); element nnn = doc.createelement("name1"); nnn.appendchild(doc.createtextnode("aaa")); sss.appendchild(nnn); element ppp = doc.createelement("phoneex"); ppp.appendchild(doc.createtextnode("cc")); sss.appendchild(ppp);
and output getting
<?xml version="1.0" encoding="utf-8" standalone="no"?> <root> <member> <name>xxx</name> <phone>vvvv</phone> <name>xxx</name> <phone>vvvv</phone> </member> <somethingnew/> </root>
but expecting somthing below, please me going wriong
<?xml version="1.0" encoding="utf-8" standalone="no"?> <root> <member> <name>xxx</name> <phone>vvvv</phone> <name>xxx</name> <phone>vvvv</phone> </member> <somethingnew> <name1>ddd</name1> <phoneex>cc</phoneex> </somethingnew> </root>
never mind able find solution, appending first element time, issue.corrected code
Comments
Post a Comment