Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
| Search | Today's Posts | Mark Forums Read
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 12th, 2007, 03:54 AM
Registered User
 
Join Date: Apr 2007
Location: chennai, tamil nadu, India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to caught
Default 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.


Similar Threads
Thread Thread Starter Forum Replies Last Post
NuSOAP Help : XML error parsing WSDL on line 2 Odys PHP How-To 0 March 16th, 2007 04:11 PM
JSTL XML parsing error pankajbrathi JSP Basics 1 August 29th, 2006 07:35 AM
Parsing URL with PHP turklet BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 November 27th, 2004 09:24 PM
XML Parsing error: require </META> disaacs XSLT 1 August 6th, 2004 01:58 PM
Parsing in PHP Walter G Pro PHP 2 August 14th, 2003 01:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.