Page 1 of 1

Array from XML

Posted: Sun Mar 04, 2007 8:23 pm
by nikemen
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I'm trying to customize a php library administration system to fit my needs. In the system, when I choose to add a book, I'm taken to a page asking to enter ISBN(ASIN). I type it and I accept, then I'm taken to a page to fill the rest of the info about the book. Well, the whole question is about lazyness: I need the system to check ISBNdb.com (a public ISBN database) for that book and fill the data for me. Till now, I've managed to check the information, but I'm an absolute newbie and I don't know how can I ask php to analyze the XML answer from ISDNdb and drop the information on an array. I don't even know how to define an array, indeed.
XML answer is something like that:
[syntax="xml"]
<ISBNdb server_time="2007-03-05T01:40:40Z">
<BookList total_results="1" page_size="10" page_number="1" shown_results="1">
<BookData book_id="works_of_oscar_wilde" isbn="1851705384">
<Title>Works of Oscar Wilde</Title>
<TitleLong/>
<AuthorsText>Oscar Wilde, Timothy Gaynor (Editor)</AuthorsText>
<PublisherText publisher_id="senate">Senate</PublisherText>
<Details dewey_decimal="" physical_description_text="800 pages" language="" edition_info="Unknown Binding; 1997-07-25" dewey_decimal_normalized="" lcc_number="" change_time="2007-03-05T00:10:26Z" price_time="2007-03-05T00:10:47Z"/>
</BookData>
</BookList>
</ISBNdb>
I need, then, to have the text between <Title> and </Title> in $o_livre->Title
the one between <AuthorsText> and </AuthorsText> in $o_livre->AuthorsText
the publisher in $o_livre->PublisherText
the text after edition_info=" and before the ; (Unknown Binding) in $o_livre->Lieu
and the date after the ; in $o_livre->ReleaseDate
I'm calling to a function in the main php file this way:[/syntax]

Code: Select all

$o_livre=get_book_isbn($rechcode)
and the function, in functions.inc, is:

Code: Select all

function get_book_isbn($rechcode)
{
$return=readfile('http://isbndb.com/api/books.xml?access_key=XXXXXXXX&results=details&index1=isbn&value1='.$rechcode);
return($return);
}
HELP PLEASE!
Many thanks for your help!


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Mar 05, 2007 12:34 am
by Chris Corbyn