I need help here to remove the xml node based on some condition
Here is my xml
<result> <product> <auto> <report> <auto> <admin></admin> <report> <search> <subjects> <subject> <name> <first>John</first> <last>D</last> </name> </subject> </subjects> </search> </report> </auto> </report> </auto> <auto> <report> <auto> <admin></admin> <report> <search> <subjects> <subject> <name> <first>Jack</first> <last>L</last> </name> </subject> </subjects> </search> </report> </auto> </report> </auto> </product> </result>
Out of this xml, based on first and last name, remove the rest of "auto" node
Keep "auto" node if First name = John and Last name = D
Expected xml:
<result> <product> <auto> <report> <auto> <admin></admin> <report> <search> <subjects> <subject> <name> <first>John</first> <last>D</last> </name> </subject> </subjects> </search> </report> </auto> </report> </auto> </product> </result>
I am tring to extract the required content first by
var query = from p in XDocument.Parse(myXml).Root.Elements ("result/product/auto/report/auto/report/search/subjects/subject/name") where ( from c in p.Elements("first") where c.Value == "John" select c ).Any() select p;
Please suggest me here.
If I understand you correctly:
Print:
Link: https://dotnetfiddle.net/ZZ2Hlr