Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I've spent 5 hours on this, Almost got it but can t go anymore

Status
Not open for further replies.

hamhairs

Programmer
May 11, 2007
1
US
I have a XML file i want to stream to my website. Its at

I have a problem because my html output from the parser has:

<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">

included as text before my descriptions. I noticed the xml has a [CDATA]. Basically i cannot figure out a way to incorporate this extra code or get rid of it. I've tried both outs.

Please set me free !! here is all my info:

THE SCRIPT:
<?php

$insideitem = false;
$tag = "";
$title = "";
$description = "";
$link = "";

function startElement($parser, $name, $attrs) {
global $insideitem, $tag, $title, $description, $link;
if ($insideitem) {
$tag = $name;
} elseif ($name == "ITEM") {
$insideitem = true;
}
}

function endElement($parser, $name) {
global $insideitem, $tag, $title, $description, $link;
if ($name == "ITEM") {
printf("<dt><b><a href='%s'>%s</a></b></dt>",
trim($link),htmlspecialchars(trim($title)));
printf("<dd>%s</dd>",htmlspecialchars(trim($description)));
$title = "";
$description = "";
$link = "";
$insideitem = false;
}
}

function characterData($parser, $data) {
global $insideitem, $tag, $title, $description, $link;
if ($insideitem) {
switch ($tag) {
case "TITLE":
$title .= $data;
break;
case "DESCRIPTION":
$description .= $data;
break;
case "LINK":
$link .= $data;
break;
}
}
}

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen(" or die("Error reading RSS data.");
while ($data = fread($fp, 4096))
xml_parse($xml_parser, $data, feof($fp))
or die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
fclose($fp);
xml_parser_free($xml_parser);

?>

The XML file is at
Here the output I'm getting:

World Series of Poker Changes Payout Structures
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">World Series of Poker officials said Tuesday that the payout schedules for the 2007 World Series ...
Press Release: eCOGRA Offers Online Gambling Fairness Testing
<p><city><place>LONDON</place></city> -- 130 Leading Casino and Poker Brands to Display eCOGRA's Software Fairness Reports <p /></p><p>The online ...
World Poker Tour Releases Season Six Schedule
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">The first tournament of the Mirage Poker Showdown began Tuesday, and with that, so did the sixth ...
World Series of Poker Issues Scam Warning
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">Harrah's Entertainment and the World Series of Poker quietly issued a warning a couple weeks ago ...
J.C. Tran Named WPT Player of the Year
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">Even though the top spot in the World Poker Tour Player of the Year race could have changed hands ...

notice the ugly stuff.

THanks in advance

Mike
 
To get rid of the unwanted [tt]<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">[/tt], you may simply change the functional line like this.
[tt]
case "DESCRIPTION":
[red]//[/red]$description .= $data;
[blue]$description .= eregi_replace("<p class=\"MsoNormal\" style=\"MARGIN: 0in 0in 0pt\">","",$data);[/blue]
break;
[/tt]
But that may be the least important thing. The problem is why don't you like that line and have that line in the xml document in the first place.

If you don't like it because it does not close and is not followed by [tt]</p>[/tt], why then you tolerate such as that part containing [tt]<p>The online ...[/tt] ? That is only for you to answer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top