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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lawrence

    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>
    <weblogConten t>
    Military forces score a breakthrough today
    </weblogContent>
    </entry>

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

    </xml>
  • Chung Leong

    #2
    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@geoci ties.com> napisal w wiadomosci
    news:da7e68e8.0 403191540.4694a 67e@posting.goo gle.com...[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>
    > <weblogConten t>
    > Military forces score a breakthrough today
    > </weblogContent>
    > </entry>
    >
    > <entry>
    > <weblogHeadline >
    > Saddam found in Iraq
    > </weblogHeadline>
    > <weblogConten t>
    > Military forces score a breakthrough today
    > </weblogContent>
    > </entry>
    >
    > </xml>[/color]


    Comment

    • Andy Hassall

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

      On 19 Mar 2004 15:40:54 -0800, lkrubner@geocit ies.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>
      > <weblogConten t>
      > Military forces score a breakthrough today
      > </weblogContent>
      ></entry>
      >
      ><entry>
      > <weblogHeadline >
      > Saddam found in Iraq
      > </weblogHeadline>
      > <weblogConten t>
      > 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

      Comment

      • Andy Hassall

        #4
        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@geoci ties.com> napisal w wiadomosci
        >news:da7e68e8. 0403191540.4694 a67e@posting.go ogle.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

        Comment

        • Chung Leong

          #5
          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:50ro50pbv3 to897q1m5h5jqvp m9fb01ehj@4ax.c om...[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@geoci ties.com> napisal w wiadomosci
          > >news:da7e68e8. 0403191540.4694 a67e@posting.go ogle.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]


          Comment

          Working...