Menu
I am trying to set up an xml feed on my webpage and need some direction on what to do. I am retrieving the xml from another website and displaying it in my html pages.
I posted a thread on the xml section of this website and got this answer:
The CURL Module will allow PHP to get the XML. Then you’ll need to use something to format the XML and insert it into your page.
Does anyone have any ideas how I can do this?
[CODE]
<response>
<query>realty</query>
<location>78745</location>
<results>
<result>
<jobtitle>Realty</jobtitle>
<company>Realty Monkey</company>
<snippet>
yoyoyoyoyoyoyoyo
</snippet>
</result>
<result>
<jobtitle>Realty2</jobtitle>
<company>Realty Monkey2</company>
<snippet>
yoyoyoyoyoyoyoyo2
</snippet>
</result>
</results>
</response>
<result>
[/CODE]
[CODE]<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<body style="font-family:Arial;font-size:12pt;>
<div style="color:#cccccc; width:300pt; height:100pt; background:#000000;">
<xsl:value-of select="query"/>
<xsl:value-of select="location"/>
<xsl:value-of select="totalresults"/>
</div>
<xsl:for-each select="response/results/result">
<div style="background-color:#ccc;">
<div style="font-weight:bold;color:teal;"><xsl:value-of select="jobtitle"/><xsl:value-of select="company"/><xsl:value-of select="city"/></div>
</div>
</xsl:for-each>
</body>
</html>[/CODE]
[CODE]<?php
$xmlDoc = new DOMDocument();
$xmlDoc->load("http://api.indeed.com/ads/apisearch?publisher=3309688785061266&q=$job&l=$zip&sort=&radius=50&st=&jt=&start=&limit=20&fromage=%20&filter=&latlong=1&co=us&chnl=&userip=1.2.3.4&useragent=Mozilla/%2F4.0%28Firefox%29");
$x = $xmlDoc->documentElement;
foreach ($x->childNodes AS $item)
{
print $item->nodeValue . "<br />";
}
?>[/CODE]
<i>
</i>echo "<div id='box'>";
foreach ($xml->response->results->result as $r) {
echo "<p class='job'>$r->jobtitle</p>";
...etc
}
echo "</div>";
Cool. I would note that there's a bit of a trade-off with the curl-vs-no-curl options here. With the current no-curl option, every time someone hits your site, your site will hit that remote site to read the xml file. Hopefully you have permission, and/or your site isn't too busy. With the curl option, you could download the xml file, say once a day, and then you wouldn't be hitting that remote site nearly as much. But your data would be up to 24 hours old.
Just mentioning it - I'm not saying there is a right or wrong way to do it, but I thought I'd throw the issue on the table.
Dave[/QUOTE]
[CODE]echo "<div id='box'>";
foreach ($xml->response->results->result as $r) {
echo "<p class='job'>$r->jobtitle</p>";
...etc
}
echo "</div>";[/CODE]
[CODE]$xml = new DOMDocument();
$xml->load("file.xml");[/CODE]
Is $xml suppose to be:
[CODE]$xml = new DOMDocument();
$xml->load("file.xml");[/CODE]
ALSO, what exactly is $r??[/QUOTE]
<i>
</i>$xml = simplexml_load_file ("http://www.example.com/feed.xml");
[CODE]<?php
$xml = simplexml_load_file ("example.xml");
foreach ($xml->response->results->result as $r) {
echo "<p class='jobXml'>$r->jobtitle</p>";
echo "<p class='companyXml'>$r->company</p>";
}
?>[/CODE]
<i>
</i>foreach ($xml->results->result as $r) {
echo "<p class='jobXml'>$r->jobtitle</p>";
echo "<p class='companyXml'>$r->company</p>";
}
[CODE]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head></head>
<body>
<?php
$xml = simplexml_load_file ("http://api.indeed.com/ads/apisearch?publisher=3309688785061266&q=$job&l=$zip&sort=&radius=50&st=&jt=&start=&limit=20&fromage=%20&filter=&latlong=1&co=us&chnl=&userip=1.2.3.4&useragent=Mozilla/%2F4.0%28Firefox%29");
foreach ($xml->results->result as $r) {
echo "<a href='$r->url' class='jobXml'>$r->jobtitle</a>";
echo "<p class='snippetXml'>$r->snippet</p>";
echo "<a href='$r->url' class='companyXml'>$r->company</a>";
}
?>
</body>
</html>[/CODE]
[code=php]
<?php
<?php
#street cred
define('AUTHOR', 'JD (Jon Daniel)');
define('MODDATE', '07232010||12:51');
define('VERSION', '0.2c');
define('OPTION', 'display');
$uri = NULL;
$uri .= 'http://feedpull.godatafeed.com/product.aspx'
$uri .= '?spud=4HQdUqLqR05943LbmAh%2b%2bIoM%2btPmtGWVEB4sF672EO8%3d';
if (($handle = fopen("$uri", "r")) !== FALSE) {
$int = 0;
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$c = count($data);
for ($x=0; $x < $c; $x++) {
$c_dim[$int][$x] = $data[$x];
}
$int++;
}
fclose($handle);
}
array_shift($c_dim); //delete head
foreach($c_dim AS $key) {
foreach($key AS $sub_key => $val) {
if ($sub_key == 6) {$n = $val;}
if ($sub_key == 2) {$m = $val;}
} $tmp[$n] = $m;
}
$tmp = array_unique($tmp);
if (OPTION == 'curl') { #CycleTime 6min
$payload = '<br />Missing Files List:';
foreach ($tmp AS $key => $val) {
$ch = curl_init($val . '?wid=171&hei=205');
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
$data = curl_exec($ch);
curl_close($ch);
if ($data === false) {
echo "cURL Failed on: $key";
exit;
}
$contentLength = 'unknown';
if (preg_match('/Content-Length: (d+)/', $data, $matches)) {
$contentLength = (int)$matches[1];
}
if ($contentLength == 4626) {
$payload .= "<br />$key : $val";
}
}
}
if (OPTION == 'display') { #CycleTime 4min
$payload = NULL; $payload .= "<div style='width:950px;'>
foreach ($tmp AS $key => $val) {
$payload .= "<div style='padding:10px 5px 0;border:solid 1px #000'>";
$payload .= "<img src='$val?wid=171&hei=205' alt='$val' />";
$payload .= "<span>$key</span></div>";
} $payload .= "</div>";
}
echo "<html><body>$payload</body></html>"; ?>
[/code]
0.1.9 — BETA 6.16