Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2010
    Posts
    54
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Getting individual information from XML array

    Mods, sorry for the double post, but I realized this is more of a PHP question than an XML question! I am trying to pull the individual pieces out of an xml array here is my php to get the xml:

    PHP Code:
    $url="http://api.campusbooks.com/11/rest/bookprices?key=bleh&isbn=9780132080231"

    $response file_get_contents($url); 
    $parsed_xml simplexml_load_string($response); 

    var_dump($parsed_xml); 
    And here is my XML (as shown by the var_dump):

    Code:
    object(SimpleXMLElement)#1 (3) {
      ["@attributes"]=>
      array(2) {
        ["status"]=>
        string(2) "ok"
        ["version"]=>
        string(2) "11"
      }
      ["label"]=>
      object(SimpleXMLElement)#2 (1) {
        ["@attributes"]=>
        array(2) {
          ["plid"]=>
          string(4) "3670"
          ["name"]=>
          string(11) "Website"
        }
      }
      ["page"]=>
      object(SimpleXMLElement)#3 (3) {
        ["@attributes"]=>
        array(1) {
          ["name"]=>
          string(10) "bookprices"
        }
        ["book"]=>
        object(SimpleXMLElement)#4 (13) {
          ["isbn10"]=>
          string(10) "0132080230"
          ["isbn13"]=>
          string(13) "9780132080231"
          ["title"]=>
          string(28) "Microeconomics (7th Edition)"
          ["author"]=>
          string(33) "Robert Pindyck - Daniel Rubinfeld"
          ["binding"]=>
          string(9) "Hardcover"
          ["msrp"]=>
          string(6) "166.67"
          ["pages"]=>
          string(3) "768"
          ["publisher"]=>
          string(13) "Prentice Hall"
          ["published_date"]=>
          string(10) "2008-06-21"
          ["edition"]=>
          string(1) "7"
          ["rank"]=>
          string(5) "58345"
          ["rating"]=>
          string(3) "3.5"
          ["image"]=>
          string(60) "http://ecx.images-amazon.com/images/I/51GLbJmZclL._SL75_.jpg"
        }
    So what is the syntax to pull out book=>edition and echo it for example? I am really struggling with this.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,864
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    It'd be easy if you give the contents of the xml file instead of var_dump() result
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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