473,324 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Parsing an XML (same TAG name)

All,
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
/TiVoVideoDetails?id=465887.

- <CustomIcon>
<Url>urn:tivo:image:save-until-i-delete-recording</Url>
<ContentType>image/*</ContentType>
<AcceptsParams>No</AcceptsParams>
</CustomIcon>
- <TiVoVideoDetails>
<Url>/TiVoVideoDetails?id=465887</Url>
<ContentType>text/xml</ContentType>
<AcceptsParams>No</AcceptsParams>
</TiVoVideoDetails>

PHP code:
<?php
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",
"_tivoend_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",
xml_error_string(xml_get_error_code($this->parser)),
xml_get_current_line_number($this->parser)));
xml_parser_free($this->parser);
return $items;
}
function _tivostart_element($parser, $name, $attribs)
{
global $depth, $currenttag, $items, $itemcount;
$depth++;
if ($name == "Url" && $depth == 5) {
$currenttag = $name;
}
}
function _tivoend_element($parser, $name)
{
global $depth, $items;
$depth--;
}
function _tivodata($parser, $data)
{
$data = str_replace("%amp;%", "&amp;", $data);
global $currenttag, $items, $itemcount;
switch ($currenttag) {
case "Url":
$items[$itemcount]['url'] = $data;
$currenttag = "";
break;
default:
break;
}
}
}
?>

Does this make sense to anyone, cause I confused as hell =)
Jul 17 '05 #1
1 2393
Yeah fuckers =) I figured it out...I'll post back soon w/my solution (it's
pretty ghetto, but it works)
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
0
by: Fabian Kr?ger | last post by:
Hello, I got a weird problem and need your help and ideas... I´ve written an php application which imports data in XML format and writes this data to a MySQL database to have a faster access....
35
by: .:mmac:. | last post by:
I have a bunch of files (Playlist files for media player) and I am trying to create an automatically generated web page that includes the last 20 or 30 of these files. The files are created every...
8
by: Dinçer | last post by:
I need to parse an XML file and print the contents of it on an aspx page. My XML file structure is like this: <QueryResult> <messageNo>1</messageNo> <messageText /> <HERE>...
8
by: pradeepsarathy | last post by:
Hi all, Does the SAX parser has eventhandlers for parsing xml schema. Can we parse the xml schema the same way as we parse the xml document using SAX Parser. Thanks in advance. -pradeep
29
by: zoltan | last post by:
Hi, The scenario is like this : struct ns_rr { const u_char* rdata; }; The rdata field contains some fields such as :
6
by: giulianodammando | last post by:
In the development of a simple numerical simulation software i need to read some initialization parameters from a file that looks like: # Global Setup species = 1; \begin{specie}<1>...
12
by: Klaus Alexander Seistrup | last post by:
Hi group, I am new to xgawk (and seemingly to xml also), and I've been struggling all afternoon to have xgawk¹ parsing an XHTML file containing a hCard², without luck. I wonder if you guys...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
2
by: Felipe De Bene | last post by:
I'm having problems parsing an HTML file with the following syntax : <TABLE cellspacing=0 cellpadding=0 ALIGN=CENTER BORDER=1 width='100%'> <TH BGCOLOR='#c0c0c0' Width='3%'>User ID</TH> <TH...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.