Click here to Skip to main content
15,897,226 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<MainParents>
      <Parent>
        <Child 1>Something</Child 1>
        <Child 2>Something</Child 2>
        <Child 3>Something</Child 3>
        <Child 4>Something</Child 4>
      </Parent>
</MainParents>

----------------------------------
i would like to remove only the "Parent" tag not its content tags in this XML can you any body help me ...
finally i need output like . . .
XML
<MainParents>
    <Child 1>Something</Child 1>
    <Child 2>Something</Child 2>
    <Child 3>Something</Child 3>
    <Child 4>Something</Child 4>
 </MainParents>
Posted
Updated 12-Jul-18 2:59am
v2

you can try like this..

1) read the <parent> tag and copy all child node using inner xml
2) now go to the root node that is MainParents
3) now replace the inner xml string with your xml string which is read in first step.

i think it will solve your problem.

but i can't under stand why you need this. you can directly access the child node by steping on the Parent tag.
 
Share this answer
 
v2
Comments
[no name] 25-Jun-12 9:10am    
Thanks to your replay , main parent is having 8 different sub parent that individual parent contains more than 10k children's , it will take more time to copy the children's and again write it . . . Is there any way to search this <Parent> </Parent> tags and replace with ""(empty string). . . or any other way . . .
try this..

foreach (XmlNode chkNode in nodes)
{                
    string currentName = "Test 1";
    if (!nameDict.ContainsKey(currentName))
    {
        XmlNode parent = chkNode.ParentNode;
        parent.ParentNode.RemoveChild(parent);
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900