Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

display parsed xml within wordpress page

Posted on 2011-10-13
4
Medium Priority
?
238 Views
Last Modified: 2012-05-12
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.
<?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;
}
?>

Open in new window

0
Comment
Question by:COwebmaster
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
jrm213jrm213 earned 1000 total points
ID: 36968724
If you view source is the source completely empty? If so that indicates a php error and with error_reporting set like that the error should be displaying if there is one.

Can you check your sites error_log, I would guess the code is causing a problem somewhere else in wordpress either with the plugin or possibly something in your php is causing a problem with the plugin.
0
 
LVL 70

Assisted Solution

by:Jason C. Levine
Jason C. Levine earned 1000 total points
ID: 36970548
Is the XML data local?  WordPress has all kinds of little security tweaks that can block things from being accessed unless you do it just right...
0
 

Author Comment

by:COwebmaster
ID: 36996155
it's just pulling in links from another site.  it can pull up just fine in a php page but not in a wp page.  It just turns up blank.  I'll check the logs
0
 

Author Closing Comment

by:COwebmaster
ID: 37120519
Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question