XML parsing

A place for developers to advertise their TheTVDB.com enabled app and get help from other developers with the API.
whw
Posts: 1
Joined: Tue May 08, 2012 11:21 am

XML parsing

Postby whw » Tue May 08, 2012 11:33 am

Hi,

I am currently trying to parse the XML returned from the getSeries.php, but the parsing won't work as I want it to.

Currently I am getting the XML with cURL

Code: Select all

$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, "$mirrorpath/api/GetSeries.php?seriesname=$show_name");


and parse it with SAX

Code: Select all

$parser=xml_parser_create();
xml_set_element_handler($parser, "openingTag","closingTag");
xml_set_character_data_handler($parser, "foundText");
xml_parse($parser,$xml);
xml_parser_free($parser);


function openingTag($parser,$tag,$attributes)
{
    global $currentTag;
    $currentTag = strtolower($tag);
}

function closingTag($parser,$tag)
{
    global $currentTag;
    $currentTag = null;
}

function foundText($parser,$characters)
{
    global $data, $currentTag;
    $data[$currentTag][] = $characters;
}



But when I want to echo the results I always get mistakes when it comes to & and '.
When there is a & in the title it is seen as a new show and ' is changed to some other symbols
and also lets the parser think it is a new show.

Code: Select all

echo "<table>";
for($count=0; $count < count($data["seriesid"]); $count++)
{
    echo "<tr>";
   echo "<td>" . $data["seriesname"][$count] . "</td>";
   echo "<td class='input'>" . $data["seriesid"][$count] . "</td>";
   echo "</tr>";
   echo "<tr>";
   
}
echo "</table>";


Does anyone have a solution for this problem?
Like letting the parser completely ignore what is between the tags.
I tried replacing &amp; with "and", but this doesn't really solve the problem for other characters.

Thanks in advance
whw

Return to “Developers”

Who is online

Users browsing this forum: No registered users and 2 guests