Sakirovicei
New Member
I have difficulty to find C# script to get certain parent element when child condition is found. For having clearer understanding, here i show you the XML :\[code\]<a> <a.1 name='First'> <a.1.1>A</a.1.1> <a.1.2> <a.1.2.1>B</a.1.2.1> <a.1.2.2> <key>C</key> </a.1.2.2> </a.1.2> </a.1></a><b> <b.1 name='Second'> <b.1.1>D</b.1.1> <b.1.2> <b.1.2.1>E</b.1.2.1> <b.1.2.2> <key>F</key> </b.1.2.2> </b.1.2> </b.1></b>\[/code\]From the XML above, I want to find 'C' and the desired result is :\[code\]<a> <a.1 name='First'> <a.1.2> <a.1.2.2> <key>C</key> </a.1.2.2> </a.1.2> <a.1></a>\[/code\]Only parent elements that have direct relation with child are shown.I have searched several links below, but they show all parent elements. Is it possible to do what I want?[*]Retrieve XML parent node attribute if child node meets a certain criteria and assign both to variables[*]C# XML, find node and all his parents