SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot mcahill's Avatar
    Join Date
    May 2002
    Location
    Manchaug, MA, USA
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XML Parsing Into Variables...again...

    A recurring theme, but I haven't been able to make any of the stuff I searched up work for me.

    Here's the situation - I have an xml file that I've got to rip apart and alter a little, then show on a webpage. I need to retrieve each resultset, with it's items, and the url of the items...and loop through to massage the url and show both a link and the image.

    PHP Code:
      <?xml version="1.0" ?> 
    - <AAAResponse>
    - <Data>
    - <Resultset Name="_COMPANY_219">
    - <Item Name="i-1.JPG">
      <Created>1136481600</Created> 
      <Modified>1136481600</Modified> 
      <ServiceType>host</ServiceType> 
      <URL>http://development.provider.com/abc/company/_COMPANY_219/i-1.JPG</URL> 
      </Item>
    - <Item Name="i-2.JPG">
      <Created>1136481601</Created> 
      <Modified>1136481601</Modified> 
      <ServiceType>host</ServiceType> 
      <URL>http://development.provider.com/abc/company/_COMPANY_219/i-2.JPG</URL> 
      </Item>
    - <Item Name="i-3.JPG">
      <Created>1136481602</Created> 
      <Modified>1136481602</Modified> 
      <ServiceType>host</ServiceType> 
      <URL>http://development.provider.com/abc/company/_COMPANY_219/i-3.JPG</URL> 
      </Item>
    - <Item Name="i-4.JPG">
      <Created>1136481603</Created> 
      <Modified>1136481603</Modified> 
      <ServiceType>host</ServiceType> 
      <URL>http://development.provider.com/abc/company/_COMPANY_219/i-4.JPG</URL> 
      </Item>
    - <Item Name="i-5.JPG">
      <Created>1136481605</Created> 
      <Modified>1136481605</Modified> 
      <ServiceType>host</ServiceType> 
      <URL>http://development.provider.com/abc/company/_COMPANY_219/i-5.JPG</URL> 
      </Item>
      </Resultset>
    - <Resultset Name="_COMPANY_222">
    - <Item Name="i-1.JPG">
      <Created>1136827507</Created> 
      <Modified>1136827507</Modified> 
      <ServiceType>host</ServiceType> 
      <URL>http://development.provider.com/abc/company/_COMPANY_222/i-1.JPG</URL> 
      </Item>
    - <Item Name="i-2.JPG">
      <Created>1136827508</Created> 
      <Modified>1136827508</Modified> 
      <ServiceType>host</ServiceType> 
      <URL>http://development.provider.com/abc/company/_COMPANY_222/i-2.JPG</URL> 
      </Item>
    - <Item Name="i-3.JPG">
      <Created>1136827511</Created> 
      <Modified>1136827511</Modified> 
      <ServiceType>host</ServiceType> 
      <URL>http://development.provider.com/abc/company/_COMPANY_222/i-3.JPG</URL> 
      </Item>
      </Resultset>
    - <Resultset Name="_COMPANY_1136905527141">
    - <Item Name="i-1.JPG">
      <Created>1136905584</Created> 
      <Modified>1136905584</Modified> 
      <ServiceType>host</ServiceType> 
      <URL>http://development.provider.com/abc/company/_COMPANY_1136905527141/i-1.JPG</URL> 
      </Item>
      </Resultset>
    - <Resultset Name="_COMPANY_1136907728359">
    - <Item Name="i-1.JPG">
      <Created>1136907760</Created> 
      <Modified>1136907760</Modified> 
      <ServiceType>host</ServiceType> 
      <URL>http://development.provider.com/abc/company/_COMPANY_1136907728359/i-1.JPG</URL> 
      </Item>
      </Resultset>
      </Data>
    - <Header>
      <Account>company</Account> 
      <BatchNum>0</BatchNum> 
      <EndTime>1136917314</EndTime> 
      <ResultCode>200</ResultCode> 
      <StartTime>1136102400</StartTime> 
      </Header>
      </AAAResponse>
    How do I create an array containing the resultsets, and then access my items? Or, I guess if I could just rip the url into an array, I could process from there, knowing that part of my url designates the resultset (the number) and is unique.

    I've got a lot of hours into this and I can tell I'm not undestanding the right way to do it....

    Oh - using a windows box, php 4.3.x, with xml turned on, but I don't see anything in PHP Info about XSL or XSLT support (so I doubt it's turned on).

    Any help appreciated...
    mcahill
    Reel-Time.com - Saltwater Fly Fishing
    The Vario Blog
    VarioCreative.com 1 2 3 4 5 6 7

  2. #2
    SitePoint Zealot mcahill's Avatar
    Join Date
    May 2002
    Location
    Manchaug, MA, USA
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Figured it out...

    FOrget about the XML functions, just use preg_match_all

    PHP Code:
    $filename "xml_files/test.xml";
    $data file_get_contents($filename);
    $newarray preg_match_all("/<URL>(.*?)<\/URL>/"$data$urls);
    print_r($newarray);//shows number of matches (good for looping)
    print "<br>";
    print_r($urls); //contains an array of the matches...to loop through... 
    mcahill
    Reel-Time.com - Saltwater Fly Fishing
    The Vario Blog
    VarioCreative.com 1 2 3 4 5 6 7

  3. #3
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you have the power to get PEAR stuff

    http://pear.php.net/package/XML_Serializer

    Highly recommended, a great package.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •