2 years ago
#73434
laxmi T
Adding new tags to existing xml file results in adding tags in single line using DOM in Java
I have been trying to update the existing XML file by adding new multiple tags. For ex as shown below in the snippet, it works perfectly in local server wherein the same solution doesn't yield the required result in another server. here I am trying to add TestTag3 and TestTag4 to existing xml.
Local server result: This is the expected one and it is working as expected in local
<process id="test">
<TestTag1>Value1</TestTag1>
<TestTag2>value2</TestTag2>
<TestTag3>YES</TestTag3>
<TestTag4>Value4</TestTag4>
</process>
Another server result: it should update in new line for every added new tags
<process id="test">
<TestTag1>Value1</TestTag1>
<TestTag2>value2</TestTag2>
<TestTag3>YES</TestTag3><TestTag4>Value4</TestTag4></process>
Java code:
private boolean addNewTag(Node node, String tagName, String tagValue, Document document) {
Element ele = document.createElement(tagName);
if(tagValue!=null){
ele.appendChild(document.createTextNode(tagValue));
node.appendChild(ele);
return true;
}else{
ele.appendChild(document.createTextNode(""));
node.appendChild(ele);
return true;
}
}
java
xml
dom
0 Answers
Your Answer