3 Replies - 1030 Views - Last Post: 03 May 2012 - 05:10 PM Rate Topic: -----

#1 sonalmac  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 83
  • Joined: 24-June 11

xml parsing error for isbndb xml file to php

Posted 03 May 2012 - 03:40 PM

I am trying to use a php proxy script to display book titles from isbn db web service. Following ajax + javascript calls a php script which retrieves data from isbn db. PHP script gives this error:


XML Parsing Error: not well-formed
Location: http://localhost/rea...e&submit=Search
Line Number 1, Column 11:biblebible<?xml version="1.0" encoding="UTF-8"?>

Javascript code:

var titlesArray = new Array();
function handleAjaxResponse(e) {
'use strict';
if(typeof e == 'undefined') e = window.event;
var ajax = e.target || e.srcElement;
//console.log(ajax);
if(ajax.readyState == 4 ) {
if ((ajax.status >=200 && ajax.status < 300) || ajax.status == 304) {
console.log(ajax.responseXML);
if(ajax.responseXML) {
console.log(ajax.responseXML);
var allBooks = ajax.responseXML.getElementsByTagName('BookData');
for(var i=0, count = allBooks.length; i<count; i++) {
titlesArray[i] = allBooks[i].getElementsByTagName('Title')[0].firstChild;
console.log(titlesArray[i]);
}
}
}

}
}


function sendValue() {
var searchTerm = document.getElementById('searchTerm');
console.log(searchTerm.value);
var ajax = getXMLHttpRequestObject();
ajax.onreadystatechange = handleAjaxResponse;
ajax.open('GET', 'isbn3.php?searchterm=' + encodeURIComponent(searchTerm.value), true);
//ajax.open('GET', './isbn3.php', true);
ajax.send(null);
// return false;
}
window.onload = function() {

'use strict';
document.getElementById('searchTerm').onkeyup = sendValue;

}



code for isbn3.php:

if(isset($_GET['searchterm']) && is_string($_GET['searchterm']))
{
//Hold the serachterm into a variable, and typecast it.:

$isbnQuery =(string) $_GET['searchterm']; 


if($isbnQuery == NULL)
{
$error[] = "You forgot to enter ISBN. Please go back and correct the error.";
}

if(empty($error))
{


$isbnData ="http://isbndb.com/api/books.xml?access_key=keyno&results=details,texts&index1=title&value1=$isbnQuery";

//$xmlData = @simplexml_load_file($isbnData); //or die("Invalid ISBN ERROR");
$xmlDoc = file_get_contents($isbnData);
//echo '<?xml version="1.0" encoding="utf-8" standalone="yes">';
header("Content-Type: application/xml");
echo $xmlDoc; //Read the entire xml document in string.

?> 




xml file is as : http://isbndb.com/data-intro.html

Is This A Good Question/Topic? 0
  • +

Replies To: xml parsing error for isbndb xml file to php

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3480
  • View blog
  • Posts: 10,025
  • Joined: 08-June 10

Re: xml parsing error for isbndb xml file to php

Posted 03 May 2012 - 05:03 PM

the problem is that you managed to get some text "biblebible" before the XML Prolog, which invalidates the XML.

the call http://isbndb.com/ap...results=details,texts&index1=title&value1=bible itself seems to be ok, so you need to check whether you echo those values in your script somewhere.
Was This Post Helpful? 0
  • +
  • -

#3 sonalmac  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 83
  • Joined: 24-June 11

Re: xml parsing error for isbndb xml file to php

Posted 03 May 2012 - 05:09 PM

no, I'm not echoing that text "biblebible" before the XML prolog. I'm sending a string value through url from a search form to php script. Depending on that searchterm, the php script brings data from isbn db, which sends an XML file.
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3480
  • View blog
  • Posts: 10,025
  • Joined: 08-June 10

Re: xml parsing error for isbndb xml file to php

Posted 03 May 2012 - 05:10 PM

but that’s what the error message says.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1