Show XML tag full path with php

broccose

New Member
Let's assume we want to process this Feed: http://tools.forestview.eu/xmlp/xml_feed.php?aid=1094&cid=1000I'm trying to show the nodes of an XML file this way: \[code\]deals->deal->dealsitedeals->deal->deal_iddeals->deal->deal_title\[/code\]This is in order to be able to process feeds that we don't know what their XML tags are. So we will let the user choose that deals->deal->deal_title is the Deal Title and will recognize it that way.I have been trying ages to do this with this code:\[code\] class HandleXML { var $root_tag = false; var $xml_tags = array(); var $keys = array();function parse_recursive(SimpleXMLElement $element){ $get_name = $element->getName(); $children = $element->children(); // get all children if (empty($this->root_tag)) { $this->root_tag = $this->root_tag.$get_name; } $this->xml_tags[] = $get_name; // only show children if there are any if(count($children)) { foreach($children as $child) { $this->parse_recursive($child); // recursion :) } } else { $key = implode('->', $this->xml_tags); $this->xml_tags = array(); if (!in_array($key, $this->keys)) { if (!strstr('>', $key) && count($this->keys) > 0) { $key = $this->root_tag.'->'.$key; } if (!in_array($key, $this->keys)) { $this->keys[] = $key; } } } }}$xml = new SimpleXMLElement($feed_url, null, true);$handle_xml = new HandleXML;$handle_xml->parse_recursive($xml);foreach($handle_xml->keys as $key) { echo $key.'<br />';}exit;\[/code\]but here's what I get instead:\[code\]deals->deal->dealsitedeals->deal_iddeals->deal_title\[/code\]See on 2nd and 3rd line the deal-> part is missing.I have also tried with this code: http://pastebin.com/FkPWXF64 but it's definitely not the best way to go and it doesn't always work.No matter how many times I couldn't do it.Any help would be highly appreciated.Warmest Regards,George Girtsou
 
Back
Top