Question

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

Was it helpful?

Solution

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);
      }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top