Hello everyone 🙂 I'm working on a script that interfaces the IngramBook.com book database with an online shopping site. Basically IngramBooks provides an API that anyone can use to query their database for a particular set of book information. They allow SOAP request for their API, but fortunately they allow a POST request too, and I went with PHP as the language that sets the parameters, and AJAX as the platform for retrieving that IngramBook.com generated XML. I'm able to grab that parameters that absolutely have to be returned, like the book price, its title and so on. The thing is, when I retrieve one of the optional parameters, like the warehouse that stocks that book (which could be an empty tag in case that warehouse does'nt stock that particular title), my XMLHTTPRequest object throws up a javascript error, in particular the "Object expected" error. Is there a function like "isset" in javascript, using which I can check whether a particular XML tag is returned or not?
What I'm using to retrieve the XML:
var xmlResponse = xmlHttp.responseXML;
// my xmlhttprequest obj is xmlHttp
xmlRoot = xmlResponse.documentElement;
// obtain arrays with book titles and ISBNs and other info
titleArray = xmlRoot.getElementsByTagName("Title"); // media title
isbnArray = xmlRoot.getElementsByTagName("ISBN"); // unique isbn no.
authorArray = xmlRoot.getElementsByTagName("Name"); // author's name
statusArray = xmlRoot.getElementsByTagName("TitleStatus"); // TitleStatus, could be empty
The following code outputs it:
var strA = '';
for(var i=0; i<titleArray.length; i++)
{
strA = strA+"<table border='0' align='left' class='tbl' cellpadding='1' cellspacing='1' width='290'><tr><td><b><a class=\"lnk\" href=\"product.php?isbn="+isbn+"\">"+titleArray.item(i).firstChild.data+"</a></b> ("+media_typeArray.item(i).firstChild.data+")</td></tr><tr><td>By: <b>"+authorArray.item(i).firstChild.data+"</b> ("+roleArray.item(i).firstChild.data+")<br></td></tr><tr><td>Publish Date: "+pubdateArray.item(i).firstChild.data+"</td></tr><tr><td>Published By: "+publisherArray.item(i).firstChild.data+"</td></tr><tr><td>Status: $"+statusArray.item(i).firstChild.data+"</td></tr></table>";
}
Any help would be appreciated, thanks. And, BTW I'm using CURL to act as a PHP proxy for me to make a cross-domain request to IngramBooks' server.