Connecting Tech Pros Worldwide Help | Site Map

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

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 04:18 AM
lawrence
Guest
 
Posts: n/a
Default what is the easiest way to get a 2D array from an XML stream?

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>

  #2  
Old July 17th, 2005, 04:19 AM
Chung Leong
Guest
 
Posts: n/a
Default 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]


  #3  
Old July 17th, 2005, 04:19 AM
Andy Hassall
Guest
 
Posts: n/a
Default 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
  #4  
Old July 17th, 2005, 04:19 AM
Andy Hassall
Guest
 
Posts: n/a
Default 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
  #5  
Old July 17th, 2005, 04:19 AM
Chung Leong
Guest
 
Posts: n/a
Default 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]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.