If you have an XML structure and want to find certain things in it, the best way to do that is with XSLT ... which is a query-language for XML. Don't write laborious code that iterates through the nested structure, because you don't have to. LibXML contains full support.