[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 265
  • Last Modified:

need xml feed to display on webpage

I have the following xml feed and need it to display the results on a web page, preferably in my wordpress page.  How would I implement that?

<?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 Insurance]]></ls:title>
                  <ls:url><![CDATA[really long url with name/pair values]]></ls:url>
                  <ls:displayUrl><![CDATA[http://www.domain.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 Insurance]]></ls:title>
                  <ls:url><![CDATA[really long url with name/pair values]]></ls:url>
                  <ls:displayUrl><![CDATA[http://www.domain.com]]></ls:displayUrl>
                  <ls:cpc>0.0442</ls:cpc>
            </ls:ssResult>
      </ls:ssResultSet>

</ls:lookSmartResults>

So the results in the page should display the title and display url (linked to url)
0
COwebmaster
Asked:
COwebmaster
  • 4
  • 2
1 Solution
 
Ray PaseurCommented:
http://www.laprbass.com/RAY_temp_cowebmaster.php

Outputs:
1 Get it at listproperty.com.au Car Insurance 0.0680
2 Get it at propertys.com.au Car Insurance 0.0442
<?php // RAY_temp_cowebmaster.php
error_reporting(E_ALL);


// TEST DATA FROM THE POST AT EE
$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 Insurance]]></ls:title>
                  <ls:url><![CDATA[really long url with name/pair values]]></ls:url>
                  <ls:displayUrl><![CDATA[http://www.domain.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 Insurance]]></ls:title>
                  <ls:url><![CDATA[really long url with name/pair values]]></ls:url>
                  <ls:displayUrl><![CDATA[http://www.domain.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;
    echo "<br/>$i $a $t $c" . PHP_EOL;
}

Open in new window

0
 
COwebmasterAuthor Commented:
thanks Ray.  Is this just a matter of placing that above code in a wordpress page?
0
 
Ray PaseurCommented:
It might take a little more than that -- I am not any kind of a WP expert.  I just wanted to show you how to get information from XML into something you can put on the browser output stream.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Jason C. LevineNo oneCommented:
Before going deep into PHP, try this plugin:

http://wordpress.org/extend/plugins/simplepie-plugin-for-wordpress/
0
 
COwebmasterAuthor Commented:
Thanks, but I installed simple pie but not sure how to get the above xml to parse and display onto a page.  Any idea on how to do that?
0
 
COwebmasterAuthor Commented:
According to their faq page here http://simplepie.org/wiki/faq/can_simplepie_parse_raw_xml_feeds it doesn't support parsing out raw xml
0
 
COwebmasterAuthor Commented:
Excellent! Thanks Ray!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now