Mike Waller
asked on
display parsed xml within wordpress page
I have the following scriot which works great on a .php page. However, I need it to work within a wordpress page but nothing displays in the page . I do have the plugin PHP Execution installed and can run a siimple php script in the (html tab) page and I can see the results in my browser. For some reason though, the following script display nothing.
Any ideas?
I do have simple pie plugin installed but have no idea how and if it can parse out xml and display it in a wp page.
Any ideas?
I do have simple pie plugin installed but have no idea how and if it can parse out xml and display it in a wp page.
<?php
error_reporting(E_ALL);
$xml = <<<XML
<?xml version="1.0" encoding="UTF-8" ?>
<ls:lookSmartResults xmlns:ls="urn:domainResults">
<ls:ssResultSet ls:firstResult="1" ls:numResults="2" ls:totalHits="2">
<ls:ssResult ls:id="1">
<ls:abstract><![CDATA[Get it at listproperty.com.au]]></ls:abstract>
<ls:title><![CDATA[Car Insurance1]]></ls:title>
<ls:url><![CDATA[really long url with name/pair values]]></ls:url>
<ls:displayUrl><![CDATA[http://www.domain1.com]]></ls:displayUrl>
<ls:cpc>0.0680</ls:cpc>
</ls:ssResult>
<ls:ssResult ls:id="2">
<ls:abstract><![CDATA[Get it at propertys.com.au]]></ls:abstract>
<ls:title><![CDATA[Car Insurance2]]></ls:title>
<ls:url><![CDATA[really long url with name/pair values]]></ls:url>
<ls:displayUrl><![CDATA[http://www.domain2.com]]></ls:displayUrl>
<ls:cpc>0.0442</ls:cpc>
</ls:ssResult>
</ls:ssResultSet>
</ls:lookSmartResults>
XML;
// MUNG THE XML TO MAKE IT WORK WELL WITH SIMPLEXML
$new = str_replace('ls:', 'ls_', $xml);
// MAKE AN OBJECT
$obj = SimpleXML_Load_String($new, 'SimpleXMLElement', LIBXML_NOCDATA);
// ACTIVATE THIS TO VISUALIZE THE OBJECT
// var_dump($obj);
// ITERATE OVER THE OBJECT TO EXTRACT AND VISUALIZE ITS CONTENTS
foreach ($obj->ls_ssResultSet->ls_ssResult as $r)
{
$i = $r["ls_id"];
$a = (string)$r->ls_abstract;
$t = (string)$r->ls_title;
$c = (string)$r->ls_cpc;
$d = (string)$r->ls_displayUrl;
$u = (string)$r->ls_url;
//echo "<br />$i $a $t $c" . PHP_EOL;
echo "$t<br /><a href=\"$u\" target=\"_blank\">$d</a><br /><br />" . PHP_EOL;
}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!
ASKER