This cone be done in a simple XPath (XPath is a subset of XQuery). The expression will be:
//*[name = 'def']/type1
This searches for all elements with a child element named name
equal to def
and returns the type1
element. Depending on your actual data you might want to change *
(a wildcard operator) to type2
, if you just want to search in type2
elements. This is not quite clear from your question.
You might also want to check the basics of XPath/XQuery as this is one of the most basic things. So if you intend to spend more time using XPath/XQuery you should make yourself more familiar with the language.