Connecting Tech Pros Worldwide Forums | Help | Site Map

what is the easiest way to get a 2D array from an XML stream?

lawrence
Guest
 
Posts: n/a
#1: Jul 17 '05
I can't quite figure out PHP's XML functions. Given an XML stream like
the one below, how do I get a 2D array?


<xml>

<entry>
<weblogHeadline>
Saddam found in Iraq
</weblogHeadline>
<weblogContent>
Military forces score a breakthrough today
</weblogContent>
</entry>

<entry>
<weblogHeadline>
Saddam found in Iraq
</weblogHeadline>
<weblogContent>
Military forces score a breakthrough today
</weblogContent>
</entry>

</xml>

Chung Leong
Guest
 
Posts: n/a
#2: Jul 17 '05

re: what is the easiest way to get a 2D array from an XML stream?


Parse the file with preg_match_all. That'll give you a 2D array.

Uzytkownik "lawrence" <lkrubner@geocities.com> napisal w wiadomosci
news:da7e68e8.0403191540.4694a67e@posting.google.c om...[color=blue]
> I can't quite figure out PHP's XML functions. Given an XML stream like
> the one below, how do I get a 2D array?
>
>
> <xml>
>
> <entry>
> <weblogHeadline>
> Saddam found in Iraq
> </weblogHeadline>
> <weblogContent>
> Military forces score a breakthrough today
> </weblogContent>
> </entry>
>
> <entry>
> <weblogHeadline>
> Saddam found in Iraq
> </weblogHeadline>
> <weblogContent>
> Military forces score a breakthrough today
> </weblogContent>
> </entry>
>
> </xml>[/color]


Andy Hassall
Guest
 
Posts: n/a
#3: Jul 17 '05

re: what is the easiest way to get a 2D array from an XML stream?


On 19 Mar 2004 15:40:54 -0800, lkrubner@geocities.com (lawrence) wrote:
[color=blue]
>I can't quite figure out PHP's XML functions. Given an XML stream like
>the one below, how do I get a 2D array?
>
>
><xml>
>
><entry>
> <weblogHeadline>
> Saddam found in Iraq
> </weblogHeadline>
> <weblogContent>
> Military forces score a breakthrough today
> </weblogContent>
></entry>
>
><entry>
> <weblogHeadline>
> Saddam found in Iraq
> </weblogHeadline>
> <weblogContent>
> Military forces score a breakthrough today
> </weblogContent>
></entry>
>
></xml>[/color]

http://uk.php.net/xml_parse_into_struct perhaps.

--
Andy Hassall <andy@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Andy Hassall
Guest
 
Posts: n/a
#4: Jul 17 '05

re: what is the easiest way to get a 2D array from an XML stream?


On Sat, 20 Mar 2004 10:35:12 -0500, "Chung Leong" <chernyshevsky@hotmail.com>
wrote:
[color=blue]
>Uzytkownik "lawrence" <lkrubner@geocities.com> napisal w wiadomosci
>news:da7e68e8.0403191540.4694a67e@posting.google. com...[color=green]
>> I can't quite figure out PHP's XML functions. Given an XML stream like
>> the one below, how do I get a 2D array?[/color]
>
>Parse the file with preg_match_all. That'll give you a 2D array.[/color]

But a 2D array of what? You cannot parse XML with a single regular expression,
they aren't capable of storing enough state information to act as an
SGML/HTML/XML parser.

To parse XML, use an XML parser.

--
Andy Hassall <andy@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Chung Leong
Guest
 
Posts: n/a
#5: Jul 17 '05

re: what is the easiest way to get a 2D array from an XML stream?


A 2D array of a XML file of a specific schema as noted in the original post.
RegExp is perfectly capable of parsing that.

Uzytkownik "Andy Hassall" <andy@andyh.co.uk> napisal w wiadomosci
news:50ro50pbv3to897q1m5h5jqvpm9fb01ehj@4ax.com...[color=blue]
> On Sat, 20 Mar 2004 10:35:12 -0500, "Chung Leong"[/color]
<chernyshevsky@hotmail.com>[color=blue]
> wrote:
>[color=green]
> >Uzytkownik "lawrence" <lkrubner@geocities.com> napisal w wiadomosci
> >news:da7e68e8.0403191540.4694a67e@posting.google. com...[color=darkred]
> >> I can't quite figure out PHP's XML functions. Given an XML stream like
> >> the one below, how do I get a 2D array?[/color]
> >
> >Parse the file with preg_match_all. That'll give you a 2D array.[/color]
>
> But a 2D array of what? You cannot parse XML with a single regular[/color]
expression,[color=blue]
> they aren't capable of storing enough state information to act as an
> SGML/HTML/XML parser.
>
> To parse XML, use an XML parser.
>
> --
> Andy Hassall <andy@andyh.co.uk> / Space: disk usage analysis tool
> http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space[/color]


Closed Thread