smithmr8 Posted May 31, 2011 Share Posted May 31, 2011 Hi, I need to get data from an XML file, like the format below: <ISBNdb server_time="2011-05-31T19:19:42Z"> <BookList total_results="1" page_size="10" page_number="1" shown_results="1"> <BookData book_id="build_your_own_database_driven_web_site_using_php_mysql_4th_" isbn="0980576814" isbn13="9780980576818"> <Title> Build Your Own Database Driven Web Site Using PHP & MySQL, 4th Edition </Title> <TitleLong/> <AuthorsText>Kevin Yank, </AuthorsText> <PublisherText publisher_id="sitepoint">SitePoint</PublisherText> <Details change_time="2009-04-02T00:30:10Z" price_time="2011-05-31T17:46:10Z" edition_info="Paperback; 2009-06-15" language="" physical_description_text="360 pages" lcc_number="" dewey_decimal_normalized="5" dewey_decimal="005"/> </BookData> </BookList> </ISBNdb> I need to know how you get the details from <title>,<AuthorsText><PublisherText> and Bookdata. Tried using the example on W3C, using simplexml_load_file but it only returns: ISBNdb BookList: Code I'm currently using is: $xml = simplexml_load_file("http://isbndb.com/api/books.xml?access_key=----&results=details&index1=isbn&value1=".$isbn); echo $xml->getName() . "<br />"; foreach($xml->children() as $child) { echo $child->getName() . ": " . $child . "<br />"; } Quote Link to comment Share on other sites More sharing options...
xyph Posted May 31, 2011 Share Posted May 31, 2011 If you print_r( $xml ); after you run simplexml_load_file you'll see how the object is built, and be able to find the objects/variables you want. Quote Link to comment Share on other sites More sharing options...
smithmr8 Posted May 31, 2011 Author Share Posted May 31, 2011 That returns this: SimpleXMLElement Object ( [@attributes] => Array ( [server_time] => 2011-05-31T19:45:34Z ) [bookList] => SimpleXMLElement Object ( [@attributes] => Array ( [total_results] => 1 [page_size] => 10 [page_number] => 1 [shown_results] => 1 ) [bookData] => SimpleXMLElement Object ( [@attributes] => Array ( [book_id] => build_your_own_database_driven_web_site_using_php_mysql_4th_ [isbn] => 0980576814 [isbn13] => 9780980576818 ) [Title] => Build Your Own Database Driven Web Site Using PHP & MySQL, 4th Edition [TitleLong] => SimpleXMLElement Object ( ) [AuthorsText] => Kevin Yank, [PublisherText] => SitePoint [Details] => SimpleXMLElement Object ( [@attributes] => Array ( [change_time] => 2009-04-02T00:30:10Z [price_time] => 2011-05-31T17:46:10Z [edition_info] => Paperback; 2009-06-15 [language] => [physical_description_text] => 360 pages [lcc_number] => [dewey_decimal_normalized] => 5 [dewey_decimal] => 005 ) ) ) ) ) What would I have to do to get it to echo out the title, and such ? Not sure how you'd go about doing that from this. Quote Link to comment Share on other sites More sharing options...
xyph Posted May 31, 2011 Share Posted May 31, 2011 If you view the source of the page or use <pre> tags, things will look better. You want something like $xml->BookList->BookData->Title $xml->BookList->BookData->AuthorsText $xml->BookList->BookData->PublisherText $xml->BookList->BookData->attributes()->book_id $xml->BookList->BookData->attributes()->isbn $xml->BookList->BookData->attributes()->isbn13 SimpleXMLElement Object ( [@attributes] => Array ( [server_time] => 2011-05-31T19:45:34Z ) [bookList] => SimpleXMLElement Object ( [@attributes] => Array ( [total_results] => 1 [page_size] => 10 [page_number] => 1 [shown_results] => 1 ) [bookData] => SimpleXMLElement Object ( [@attributes] => Array ( [book_id] => build_your_own_database_driven_web_site_using_php _mysql_4th_ [isbn] => 0980576814 [isbn13] => 9780980576818 ) [Title] => Build Your Own Database Driven Web Site Using PHP & MySQL, 4th Edition [TitleLong] => SimpleXMLElement Object ( ) [AuthorsText] => Kevin Yank, [PublisherText] => SitePoint [Details] => SimpleXMLElement Object ( [@attributes] => Array ( [change_time] => 2009-04-02T00:30:10Z [price_time] => 2011-05-31T17:46:10Z [edition_info] => Paperback; 2009-06-15 [language] => [physical_description_text] => 360 pages [lcc_number] => [dewey_decimal_normalized] => 5 [dewey_decimal] => 005 ) ) ) ) ) MOD EDIT: code tags fixed . . . Quote Link to comment Share on other sites More sharing options...
smithmr8 Posted May 31, 2011 Author Share Posted May 31, 2011 Excellent. Thank-you very much! Quote Link to comment Share on other sites More sharing options...
smithmr8 Posted June 22, 2011 Author Share Posted June 22, 2011 How would you go about seperating the projects within this structure ? Array ( [projects] => Array ( [project] => Array ( [id] => 316431 [name] => My Sample Project [iteration_length] => 1 [week_start_day] => Monday [point_scale] => 0,1,2,3 [account] => Luke [first_iteration_start_time] => 2011/06/06 07:00:00 UTC [current_iteration_number] => 3 [enable_tasks] => true [velocity_scheme] => Average of 3 iterations [current_velocity] => 8 [initial_velocity] => 10 [number_of_done_iterations_to_show] => 12 [labels] => admin,blog,cart,checkout,deployment,design,epic,featured products,ie6,needs discussion,orders,reporting,search,shopper accounts,shopping,signup / signin,usability,user generated content [allow_attachments] => true [public] => false [use_https] => false [bugs_and_chores_are_estimatable] => false [commit_mode] => false [memberships] => Array ( [membership] => Array ( [id] => 1002639 [person] => Array ( [email] => smithmr8@hotmail.co.uk [name] => Luke [initials] => LU ) [role] => Owner ) ) [integrations] => Array ( ) ) ) ) Would like to be able to seperate each project, and then detail each project and it's respective attributes individually Any ideas ? Quote Link to comment Share on other sites More sharing options...
xyph Posted June 23, 2011 Share Posted June 23, 2011 There's only one project in that array. Try viewing the source of the page for better formatting. Array ( [projects] => Array ( [project] => Array ( [id] => 316431 [name] => My Sample Project [iteration_length] => 1 [week_start_day] => Monday [point_scale] => 0,1,2,3 [account] => Luke [first_iteration_start_time] => 2011/06/06 07:00:00 UTC [current_iteration_number] => 3 [enable_tasks] => true [velocity_scheme] => Average of 3 iterations [current_velocity] => 8 [initial_velocity] => 10 [number_of_done_iterations_to_show] => 12 [labels] => admin,blog,cart,checkout,deployment,design,epic,featured products,ie6,needs discussion,orders,reporting,search,shopper accounts,shopping,signup / signin,usability,user generated content [allow_attachments] => true [public] => false [use_https] => false [bugs_and_chores_are_estimatable] => false [commit_mode] => false [memberships] => Array ( [membership] => Array ( [id] => 1002639 [person] => Array ( [email] => smithmr8@hotmail.co.uk [name] => Luke [initials] => LU ) [role] => Owner ) ) [integrations] => Array ( ) ) ) ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.