Solved

parse invalid RSS feed with no root elements to tranform into useable XML data

Posted on 2010-11-09
2
475 Views
Last Modified: 2013-11-18
I have a feed that is not valid RSS nor standard and can not be changed. I would like to pull elements of this feed like recent snow fall and current temperature.

Can anyone tell me what I need to do to pull the data from this feed:
http://common.snow.com/adminincludes/rtp.resorts.vri.xml.asp

I'm using Zend_Feed_Reader but I get an error that says the Feed is Invalid or not supported.

I've also tried Zend_Dom_Query to get the data but I'm stuck in the arrays and am not sure how to pull that data out. I thought maybe there was an easier way to do this through XSL Transformation or something of the like.

Thanks for any guidance.
0
Comment
Question by:kent3800
2 Comments
 
LVL 4

Author Comment

by:kent3800
ID: 34098235
Here is an example of my path down Dom_Query land:

$url = 'http://common.snow.com/adminincludes/rtp.resorts.vri.xml.asp';
            $client = new Zend_Http_Client($url);
            $response = $client->request();
            $html = $response->getBody();
            $dom = new Zend_Dom_Query($html);
            
            if(sizeof($dom->query('resort')) > 0) {
                  $resort = $dom->query('resort');
            } else {
                  $resort = NULL;
            }
            
            if($resort != NULL) {
                  foreach($resort as $index=>$result) {
                        if($result->nodeValue !== '') {
                              $resort = $result->nodeValue;
                        }
                  }
            }
            
            $data = array(
                  'resort'=>$resort,
                  'other'=>'variable'
            );
            $xml = (object) $data;
            var_dump($xml); die;

This is the dump with $resort not holding any data:
object(stdClass)#53 (2) { ["resort"]=> string(27) " " ["other"]=> string(8) "variable" }

Thanks
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 34101167
Did you ask Jeff about how other customers use the feed?
http://www.rtp.com/company/our-people-difranco.aspx

The XML is fairly "information-dense" (a good thing!) and I do not see anything wrong with it.  Install this code snippet and run it to see how this works.  Note the use of the "commented out" var_dump() commands - those are very helpful when you are debugging data-dependent issues.

Best of luck with it, ~Ray
<?php // RAY_temp_kent3800.php
error_reporting(E_ALL);

// MAKE var_dump() EASY TO READ
echo "<pre>";

// GET THE XML FROM THE WEB SERVICE AND MAKE AN OBJECT
$url = 'http://common.snow.com/adminincludes/rtp.resorts.vri.xml.asp';
$xml = trim(file_get_contents($url));
$obj = SimpleXML_Load_String($xml);

// ACTIVATE THIS TO SEE THE OBJECT
// var_dump($obj);

// GET INFORMATION FROM THE OBJECT
foreach ($obj->resort as $r)
{
    // var_dump($r);
    $d = $r["description"];
    $s = $r->snowreport;
    // var_dump($s);
    $t = $s->temperature;
    $n = $s->newsnow;
    $f = (string)$s->temperature["fahrenheit"];
    $l = (string)$n->last24hours["inches"];

    // REPORT THE CONDITIONS
    echo PHP_EOL . "$d  {$f}&deg;F, {$l}\" NEW SNOW";
}

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Wordpress Plugin - Search From Action to Another Plugin file 13 47
write screen output to text file 21 47
error log using ftp 7 40
Curl & PHP Command Help 4 23
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

776 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