JustinK101 Posted September 2, 2009 Share Posted September 2, 2009 I am trying to loop through a multi-leveled XML structure looking for a particular node. Here is what I have: foreach($xml->children() as $child) { if($child->getName() == "subsuba") { return $child; break; } } This works fine is the XML strucuture is flat, for example like: <a>value a</a> <b>value b</b> <c>value c</c> But I have a multi-leveled XML strucuture like: <a> <suba> <subsuba>value a</subsuba> </suba> </a> <b> <subb>value b</subb> </b> <c>value c</c> So what happens is the first loop through children() is acutally another SimpleXMLObject and it just stops. How do I make this work? Link to comment https://forums.phpfreaks.com/topic/172906-looping-through-a-simplexmlelement-to-find-a-node/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.