How to store child to child nodes and remove the immediate parent?

AZH

New Member
We are parsing an xml and after serializing them ,it will be stored in database.Our XML is look like below.\[code\]<SampleTypeService> <Name>sample1</Name> <URL>sample1</URL> <SampleTypeService_PK_ID>225d0266-e83a-44b8-88fc-700f6570d530</SampleTypeService_PK_ID> <SampleTypes> <SampleType_PK_ID>ef1d8c40-72ce-48d8-b252-9b521e96fa74</SampleType_PK_ID> </SampleTypes></SampleTypeService><SampleTypeService> <Name>sample2</Name> <URL>sample2</URL> <SampleTypeService_PK_ID>225reg66-e83a-44b8-88fc-700f6570d530</SampleTypeService_PK_ID> <SampleTypes> <SampleType_PK_ID>gh4d8c40-72ce-48d8-b252-9b521e96fa74</SampleType_PK_ID> </SampleTypes></SampleTypeService>\[/code\]We need to store the value in \[code\]SampleType_PK_ID\[/code\] in a string and then remove both \[code\]SampleTypes\[/code\] and \[code\]SampleType_PK_ID\[/code\] node.I am trying to delete it like below.\[code\]foreach (XmlNode SampleNode in SampleList){ XmlNodeList ChildList = SampleNode.ChildNodes; for (int j = 0; j < ChildList.Count; j++) { if (ChildList[j].LocalName == "SampleType_PK_ID>") { strSampleTypePKID = ChildList[j].InnerText; if (strSampleTypePKID != null) { SampleNode.ParentNode.RemoveChild(ChildList[j]); j--; } } } testString = SampleNode.OuterXml; Console.WriteLine("1):" + strSampleTypePKID); //Code to serialize and store in database is here.}\[/code\]But \[code\]strSampleTypePKID\[/code\] is returning as empty string. What am I missing here. How to take the child to child node value and then delete it along with it's immediate parent?
 
Back
Top