Results 1 to 2 of 2

 

Thread: XML experts: Getting multiple attributes from an element?

  1. #1
    Registered User

    Status
    Offline
    Join Date
    Apr 2010
    Posts
    77
    Thanks
    2
    Thanked 3 Times in 2 Posts


    This is driving me bonkers. Why can't I get all attibutes from an element?
    I'm not a big expert on XML but I've got by until now.

    Here is a sample of the Dixons product feed:

    <merchantProductFeed>
    <merchant id="1597">
    <prod id="113458948" in_stock="yes">
    <pId>00776063</pId>
    <price>
    <buynow>449.99</buynow>
    </price>
    </prod>
    </merchant>
    </merchantProductFeed>


    I can get the price and the PID no problem. I can get the merchant ID (1597) and the prod id (113458948) but I can't get the in_stock attribute.

    I am using this to get the attribute id from each prod element:
    (this basic example just echoes to the screen for testing purposes)

    foreach ($products_file->merchant->prod as $prod) {
    echo "PID=" . $prod->pId . "<br>"; //works ok!
    echo "£" . $prod->price->buynow . "<br>"; //works ok!
    echo $prod->attributes()->id . "<br>"; //works ok!
    }


    So
    echo $prod->attributes()->in_stock . "<br>";
    products a blank string. Any ideas please?

  2. #2
    Registered User

    Status
    Offline
    Join Date
    Apr 2010
    Posts
    77
    Thanks
    2
    Thanked 3 Times in 2 Posts
    My mistake, the original gzip file containing the xml file didn't have the in_stock value specified!



Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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
  •  
To Top

Content Relevant URLs by vBSEO 3.5.0 RC2