Solved

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

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now