Save time and hair. Use an XPath expression to directly query the XML structure for the nodes that contain the specific attribute that you want ... anywhere and everywhere in the entire structure. LibXML can do that. Solve the difficult programming problem by avoiding it entirely.