Reputation: 215
I am Adding Some 3 elements to Root element using (We are using .Net 2.0)
xnode.AppendChild(parentINode);
xnode.AppendChild(config.CreateTextNode("\r\n"));
//then removeing all added elements using
xnode.ParentNode.RemoveChild(xnode);
This Will Add a whitespace, I want to remove whitespace that were addedd by adding elements, while removing the childnode.
My original file looks as below:
<c123:Places State="Mine">
<!-- Names-places -->
</c123:Places>
We will Be adding some elements to it :
<c123:Images State="mine">
<!-- Names-Places -->
<Name place=11111>
<Name place=22222>
</c123:Places>
Then we will delete elements :then it looks as below
<c123:Images State="Mine">
<!-- Names-Images -->
</c123:Images>
Here we are getting number of white spaces equal to number of elements added, we want to remove/Avoid the white space created after deleting child nodes.
Thanks & Regards,
Channabasappa M
Upvotes: 1
Views: 433
Reputation: 215
I Did Just Traversing to XML tag then Removed whitespace with checking
//Removing whitespace created
if (xnode.NextSibling != null && xnode.NextSibling.NodeType == XmlNodeType.Whitespace)
{
xnode.ParentNode.RemoveChild(xnode.NextSibling);
}
Upvotes: 1