473,395 Members | 1,680 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,395 software developers and data experts.

Aaargh - XML parsing!

Hello!

I've looked and searched and tried to find information about how to solbve this
problem, but I can't. I'm beginning to think that I should start from scratch
to do it right.

I am trying to parse the data from the weather channel in PHP. A slice of the
data looks like this:

<weather ver="2.0">
<cc>
<lsup>3/4/05 8:50 AM Local Time</lsup>
<obst>Vasteras, Sweden</obst>
<tmp>-7</tmp>
<flik>-12</flik>
<t>Mostly Cloudy</t>
<icon>28</icon>
<bar>
<r>1,010.8</r>
<d>steady</d>
</bar>
<wind>
<s>10</s>
<gust>N/A</gust>
<d>180</d>
<t>S</t>
</wind>
<hmid>83</hmid>
<vis>10.0</vis>
<uv>
<i>0</i>
<t>Low</t>
</uv>
<dewp>-9</dewp>
<moon>
<icon>22</icon>
<t>Waning Half, Last Quarter</t>
</moon>
</cc>
</weather>

Now, <cc> is "Current Conditions" and that's the part I would want to fetch. IN
order to read this and handle it in PHP I would very much like to read all the
data into an array. In other words, I would like the above in this format:

Array
(
[weather] => Array
(
[ver] => 2.0
[cc] => Array
(
[lsup] => >3/4/05 8:50 AM Local Time
[obst] => Vasteras, Sweden
[tmp] => -7
[flik] => -12
[t] => Mostly Cloudy
[icon] => 28
[bar] => Array
(
[r] => 1,010.8
[d] => steady
)
[wind] => Array
(
[s] => 10
[gust] => N/A
[d] => 180
[t] => S
)
[hmid] => 83
[vis] => 10
[uv] => Array
(
[i] => 0
[t] => Low
)
[dewp] => -9
[moon] => Array
(
[icon] => 22
[t] => Waning Half, Last Quarter
)
)
)
)
Which obviously would be the same as defining it like this:

$data = array(
"weather" => array(
"ver" => "2.0",
"cc" => array(
"lsup" => ">3/4/05 8:50 AM Local Time",
"obst" => "Vasteras, Sweden",
"tmp" => "-7",
"flik" => "-12",
"t" => "Mostly Cloudy",
"icon" => 28,
"bar" => array(
"r" => "1,010.8",
"d" => "steady"
),
"wind" => array(
"s" => 10,
"gust" => "N/A",
"d" => 180,
"t" => "S"
),
"hmid" => 83,
"vis" => 10.0,
"uv" => array(
"i" => 0,
"t" => "Low"
),
"dewp" => "-9",
"moon" => array(
"icon" => 22,
"t" => "Waning Half, Last Quarter"
)
)
)
);
Is there ANY way to get the XML data in to this format in a easy and painless
way? I would very much like to just have it this way:

$data = xml_to_array($xmldata);

Thanks for any help!

--
Sandman[.net]
Jul 17 '05 #1
1 1481
PHP has some built in XML functionality, or you can use one of several
other packages. I'm personally a big fan of DOM XML. It's reasonably
easy to use and seems to work pretty well. Check out:

http://www.php.net/manual/en/ref.domxml.php

Jul 17 '05 #2

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

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
2
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
16
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
0
by: Pentti | last post by:
Can anyone help to understand why re-parsing occurs on a remote database (using database links), even though we are using a prepared statement on the local database: Scenario: ======== We...
9
by: ankitdesai | last post by:
I would like to parse a couple of tables within an individual player's SHTML page. For example, I would like to get the "Actual Pitching Statistics" and the "Translated Pitching Statistics"...
5
by: randy | last post by:
Can some point me to a good example of parsing XML using C# 2.0? Thanks
3
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
7
by: Daniel Fetchinson | last post by:
Many times a more user friendly date format is convenient than the pure date and time. For example for a date that is yesterday I would like to see "yesterday" instead of the date itself. And for...
1
by: eyeore | last post by:
Hello everyone my String reverse code works but my professor wants me to use pop top push or Stack code and parsing code could you please teach me how to make this code work with pop top push or...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.