troubleshooting Question

How to get a remote XML, extract the data and show them on my PHP page?

Avatar of John_fresh
John_fresh asked on
Programming Languages-Other
1 Comment1 Solution410 ViewsLast Modified:
I need to extract data from this XML-feed: http://ads-cdn.unibet.com/orval/feed/PokerTournaments.xml
And make the extracted and formatted data appear on a PHP page, a page I will include either via PHP or as IFRAME into a wordpress page.
I have tried DOM and simple xml, but it will not work, I just get a blank page. The only thing I got to work is in the "code" below, but here it only shows 3 records, and I dont know why?? I want to determine the number of records shown.

I have also made a XSL-file for transformation. This file is pasted below the PHP code in the "code" field. Togetehr with a PHP file I hoped it would parse the XML-file, but all I got as a BLANK window. Can you see what is wrong with this?
<?php
 
// read xml file into string
$text = file_get_contents("http://ads-cdn.unibet.com/orval/feed/PokerTournaments.xml");
 
if(!$text) {
die("ERROR: Unable to read file");
}
 
// parse the xml into structure
$p = xml_parser_create();
xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0);
xml_parse_into_struct($p, $text, $vals, $index);
xml_parser_free($p);
 
// read data of interest from structure into array:
for($i=0; $i<$index['Tournament'][1]; $i++)
{
foreach(array('Name', 'GameType', 'BuyInAmount', 'date', 'Status') as $key)
{
$data[$i][$key] = $vals[$index[$key][$i]]['value'];
}
}
 
// output HTML:
foreach($data as $val)
{
echo <<<XML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
// I KNOW THE FORMATTING BELOW IS SICK, JUST WANTED TO TEST IF IT WORKED
<h3><a href="{$val['BuyInAmount']}" title="{$val['Name']}">{$val['Name']}</a></h3>
<p>{$val['date']}</p>
<a href="{$val['BuyInAmount']}" title="{$val['Name']}"><small>{$val['GameType']}</small></a>
XML;
}
?>
 
THE XSL:
 
<?xml version="1.0" encoding="utf-8"?><!-- DWXMLSource="PokerTournaments.xml" --><!DOCTYPE xsl:stylesheet  [
	<!ENTITY nbsp   "&#160;">
	<!ENTITY copy   "&#169;">
	<!ENTITY reg    "&#174;">
	<!ENTITY trade  "&#8482;">
	<!ENTITY mdash  "&#8212;">
	<!ENTITY ldquo  "&#8220;">
	<!ENTITY rdquo  "&#8221;"> 
	<!ENTITY pound  "&#163;">
	<!ENTITY yen    "&#165;">
	<!ENTITY euro   "&#8364;">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<xsl:template match="/">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Kommende pokerturneringer</title>
</head>
 
<body>
<table width="700" border="1" cellspacing="2" cellpadding="3">
  <tr>
    <td>Turneringsnavn</td>
    <td>Pokertype</td>
    <td>Innstegspris</td>
    <td>Registrerte spillere</td>
    <td>Status</td>
    <td>Startdato</td>
  </tr>
  <xsl:for-each select="Poker/Tournament">
    <tr>
      <td><xsl:value-of select="Name"/></td>
      <td><xsl:value-of select="GameType"/></td>
      <td><xsl:value-of select="BuyInAmount"/></td>
      <td><xsl:value-of select="RegisteredPlayers"/></td>
      <td><xsl:value-of select="Status"/></td>
      <td><xsl:value-of select="StartDate"/></td>
    </tr>
  </xsl:for-each>
 
 
</table>
 
 
</body>
</html>
 
</xsl:template>
</xsl:stylesheet>
ASKER CERTIFIED SOLUTION
Tobias

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros