473,396 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

weather file - accessing xml data

z1
hi -
i downloaded some data from a weather service that is in an xml file.
["parameters"]=object(SimpleXMLElement)#9 (4) { ["temperature"]=array(2)
{ [0]=object(SimpleXMLElement)#11 (2) { ["name"]=string(25) "Daily
Maximum Temperature" ["value"]=array(6) { [0]=>
object(SimpleXMLElement)#16 (0) { } [1]=string(2) "84" [2]=string(2)
"89" [3]=string(2) "87" [4]=string(2) "82" [5]=string(2) "78" } }
[1]=object(SimpleXMLElement)#12 (2) { ["name"]=string(25) "Daily Minimum
Temperature" ["value"]=array(5) { [0]=string(2) "48" [1]=string(2)
"54" [2]=string(2) "61" [3]=string(2) "60" [4]=string(2) "61" } } }

i need to get the temperatures out of that with simplexml methods.

i just cant come up with the syntax to access the array indexes of each
element of a given object.

any help is very cool.
thank you,
jim
Sep 24 '07 #1
2 1469
z1
hi -

i am going to try to use regular expressions to get my values.
i am frustrated that the formart of the file doesnt seem to be
able to be parsed by simplexml.

thanks anyways,
jim
Sep 24 '07 #2

"z1" <my@email123.netwrote in message
news:46***********************@roadrunner.com...
hi -

i am going to try to use regular expressions to get my values.
i am frustrated that the formart of the file doesnt seem to be
able to be parsed by simplexml.

thanks anyways,
listen jim, don't try to access the arrays by index. just use a foreach.
however, if you just want to use regex for simplicity and you don't need to
know attributes and such, try these:

==========

hint: segment is a node

<?xml>
<root>
<recordswould be a 'segment'...a 'single segment'
<record /would be one of many 'segments', or 'multiple segments'
<record />
<record />
</records>
</root>

$records = getSingleSegment('records', $xml);
$records = getMultipleSegments('record', $records);
foreach ($records as $record)
{
// you get the idea
}

==========

function getMultipleSegments($segment, $xml)
{
$pattern = "/<(" . $segment . ")>(.*?)<\/\\1>/si";
preg_match_all($pattern, $xml, $matches);
foreach ($matches[2] as $content)
{
$output[] = $content;
}
return $output;
}

function getMultipleSegmentNames($xml)
{
$output = array();
$pattern = "/<([^>]+)>.*?<\/\\1>/si";
preg_match_all($pattern, $xml, $matches);
foreach ($matches[1] as $content)
{
$output[] = $content;
}
return $output;
}

function getSegmentValue($xml, $emptyDefault = '')
{
$pattern = "/<([^>]+)>(.*?)<\/\\1>/si";
preg_match($pattern, $xml, $match);
$value = $match[2];
if ($value == ''){ $value = $emptyDefault; }
return htmlDecode($value);
}

function getSingleSegment($segment, $xml)
{
$output = '';
$pattern = "/<(" . $segment . ")>(.*?)<\/\\1>/si";
preg_match_all($pattern, $xml, $matches);
foreach ($matches[0] as $content)
{
$output .= $content;
}
return $output;
}

function getSingleSegmentName($xml)
{
$output = '';
$pattern = "/<([^>]+)>.*?<\/\\1>/si";
preg_match($pattern, $xml, $match);
return $match[1];
}
Sep 24 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: JamesLomuscio | last post by:
To all who know C++, Im working on a prog that will be able to predict the weather, its too complicated to go into here, but I do need some help. I need to grab all of the information in the...
3
by: Neal | last post by:
VC++ VS 2003 I am currently finishing up a weather bug program that receives data from the weather.com weather feed, just need some finishing touches. The one issue I have run into seems to be...
9
by: Boki | last post by:
Hi All, I am going to create a personal weather board. It is easy to show the picutre on website ( just link the picture to picturesbox's properties ) but I dont' know how to add some other...
1
by: pmclinn | last post by:
I have the xml feed belowfrom this link: http://www.weather.gov/alerts/ct.rss I for the life of me can not get this data to format in a html table using client side scripting. Any help would be...
4
by: Jake G | last post by:
Hi all, I am trying to get a current weather conditions feed working. Yahoo provides a free feed @ http://weather.yahooapis.com/forecastrss?p=XXXXX where XXXXX is a valid US zip code e.g....
2
by: seancron | last post by:
Does anybody have any suggestions for getting started on desigining a desktop weather application in Python? I've been looking for access to weather data and while I have found several including...
4
by: shaynenash | last post by:
I wrote this script to calculate if water restrictions were in place if it was hotter than 25deg C. It has turned out to be a pretty good weather widget that can be used elsewhere. This was initially...
2
by: Craig M | last post by:
Our current intranet site displays the weather with a 7 day forecast. We have to manually enter all the weather info into a SQL DB using a web front end, but would like to use an RSS feed. All...
1
by: akumar8k | last post by:
when i am excusing the below code i am getting the error. Error 1 − <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> − <SOAP-ENV:Body> −
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.