Parsing an XML (same TAG name)

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am stuck processing an XML file. The problem I am having, is I have the
same TAG name - Url - at the same depth, so the value from the last Url read
in is what get saved. I have tried every option I can think of to put each
URL tag into its own variable, without any luck.

I removed portions of the code that does not affect the outcome (for a
smaller post).
Here's a snippet of the XML, and when the code (below) runs, no matter what,
the value of $items[$itemcount]['url'] is always

- <CustomIcon>
- <TiVoVideoDetails>

PHP code:
class Tivo_XML {
var $dvr;
function parseTiVoXML()
global $items;
$this->parser = xml_parser_create();
xml_set_object($this->parser, &$this);
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false);
xml_set_element_handler($this->parser, "_tivostart_element",
xml_set_character_data_handler($this->parser, "_tivodata");
$file = $this->dvr . "_nowplaying.xml";
$tivoxmlstr = file_get_contents ($file);
$tivoxmlstr = str_replace("&amp;", "%amp;%", $tivoxmlstr);
xml_parse($this->parser, $tivoxmlstr , true) or
die (sprintf("XML Error: %s at line %d",
return $items;
function _tivostart_element($parser, $name, $attribs)
global $depth, $currenttag, $items, $itemcount;
if ($name == "Url" && $depth == 5) {
$currenttag = $name;
function _tivoend_element($parser, $name)
global $depth, $items;
function _tivodata($parser, $data)
$data = str_replace("%amp;%", "&amp;", $data);
global $currenttag, $items, $itemcount;
switch ($currenttag) {
case "Url":
$items[$itemcount]['url'] = $data;
$currenttag = "";

Does this make sense to anyone, cause I confused as hell =)

Re: Parsing an XML (same TAG name)

Yeah fuckers =) I figured it out...I'll post back soon w/my solution (it's
pretty ghetto, but it works)

Site Timeline