Stuck with XML

    Date: 08/30/05 (PHP Community)    Keywords: php, xml, database


    I have an XML file with a format similar to what follows:


      
          Item Title
          Item Description
          Item Size
         
             ##
             ##
             ##
         

         
             ##
             ##
             ##
         

         
             ##
             ##
             ##
         

       

      
         .
         .
       




    Having never had to parse XML before, I did some searching and found very quickly and easily how to pull information out of the first node, such as a list of titles, descriptions, or sizes, but the data I want to report is:

    Item1: Size, avgMonthlysales
    Item2: Size, avgMonthlysales
    etc.

    preferably with each value in a separate array so they could be easily called as $item[x], $size[x]...

    I'm using PHP5, so I've been working with the simplexml functions, although I have worked with the older xml functions. I haven't figured out how to get the data from the monthlysales under each corresponding item.

    Any pointers as to where I can look for more information on this? Thanks.


    Edit: I'm a little closer, but still need some help. I discovered all of the operators that work with xpath.

    Here's my (borrowed) code:

    $result = $xml->xpath('item/title | item/size | item/monthlysales/avg');
    while (list( ,$node) = each($result)){
    echo $node.'
    ';
    }

    This gives me a very nice
    Item1
    Size
    avgMonthylsales.

    I'd still like to make these into separate arrays because I want to compare them individually with existing database entries, and here is where I'm not smart enough and request help.

    Source: http://www.livejournal.com/community/php/340072.html

« Sorting an array || Getting Windows user name »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home