Solved

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

Posted on 2010-11-09
2
476 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

830 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