Error in php xml parsing...
The following is a part of the php code(which i call through ajax from javascript) to parse a simple xml document;
//---------------
$xml_handle=new DOMDocument();
$xml_handle->load("cmtyName_avail.xml");
$root=$xml_handle->getElementsByTagName("result");
if( strcasecmp($cmty_name_already_exists,"yes")==0 ){
$msg=$root->childNodes->items[0]->firstChild->nodeValue;
//$msg=$root->childNodes->items[0]->firstChild->text;
echo $msg;
}
else{
$msg=$root->childNodes->items[1]->firstChild->nodeValue;
//$msg=$root->childNodes->items[1]->firstChild->text;
echo $msg;
}
//----------------
the errors i come across are;
cannot instantiate non-existent class:domdocument in <filepath>.
followed by;
Unspecified error
code:0
url:<the .php file where i have the ajax function>.
for reference here is the xml document;
//----------------------
<?xml version="1.0" encoding="iso-8859-1"?>
<result>
<msg>
There is already a community in the same name(from xml doc)
</msg>
<msg>
Chosen community name available.Fill other details(from xml doc)
</msg>
</result>
//-------------
for reference here is the javascript/ajax function i use to call the php code;
//------------------
function check_cmtyName(){
var cmtyName=document.getElementById("id_name").value;
var httpRequest;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
httpRequest = new XMLHttpRequest();
if (httpRequest.overrideMimeType) {
httpRequest.overrideMimeType('text/xml');
// See note below about this line
}
}
else if (window.ActiveXObject) { // IE
try {
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {}//try
}//try
}// if (window.XMLHttpRequest)
if (!httpRequest) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}// if (!httpRequest)
httpRequest.onreadystatechange = function() { alertContents(httpRequest); };
var get_url="check_cmty_name_avail.php?cmty_name="+cmt yName;
httpRequest.open('GET', get_url, true);
httpRequest.send(null);
// httpRequest.open('POST', url, true);
// httpRequest.send(post_arg);
httpRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
httpRequest.setRequestHeader('Content-Type','text/xml');
}//function check_cmtyName()
function alertContents(httpRequest) {
if (httpRequest.readyState == 4) {
if (httpRequest.status == 200) {
alert(httpRequest.responseText);
//document.getElementById('id_msg_cmtyName').innerHT ML=httpRequest.responsetext;
}
else {
alert('There was a problem with the request.');
}// if (httpRequest.status == 200)
}// if (httpRequest.readyState == 4)
}// function alertContents(httpRequest)
//------------------
regards,
caught.
|