?
Solved

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

Posted on 2010-11-09
2
Medium Priority
?
479 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 111

Accepted Solution

by:
Ray Paseur earned 2000 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

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
This article discusses how to implement server side field validation and display customized error messages to the client.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

801 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