Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

760 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

20 Experts available now in Live!

Get 1:1 Help Now