hi im trying to parce a XML that is generated by a php page, the problem is that when i try to get the elements on that XML, the browser says that my variables (dado) are undefined....
any idea how to solve this?

function leValorXML(xmldoc, tag){
	var dado = xmldoc.getElementsByTagName(tag);
	var valor="";
	if (browser.nav){
		dado[0].hasChildNodes()===true ? valor=dado[0].firstChild.nodeValue : valor="";
	}else{
		dado[0].hasChildNodes()===true ?valor=dado[0].childNodes[0].nodeValue : valor="";
	}
	return valor;
}

You must declare it first, with the following instance of : var dado = xmlDoc.responseXML.getElementsByTagName( tag );

You must declare it first, with the following instance of : var dado = xmlDoc.responseXML.getElementsByTagName( tag );

tested this code, but the answer was: undefined function: responseXML
so i still with the same problem...

Include this script on the page, in which you are generating the ajax call.

<script type="text/javascript">
<!--
var leValorXML = function( tag ) {
   if ( this.readyState === 4 ) {
      if ( this.status === 200 ) {
         try {
         var dado = this.responseXML.getElementsByTagName( tag );
         var valor = "";
         return ( valor = (( !!browser.nav === true && dado[ 0 ].hasChildNodes()) ? dado[ 0 ].firstChild.nodeValue : dado[ 0 ].childNodes[ 0 ].nodeValue ));
         } catch( error ) {
            alert((( error.description ) ? error.description : (( error.message ) ? error.message : "Try to check your other functions', it might have some faulty lines..." )), "AJAX Request Failed!" );
         } 
      }
   }
};

var XHR = function( method, url, callback ) {
   this.createRequest = null;
   this.xml = 0;
   this.method = method || "GET";
   this.url = url || null;
   this.callback = callback || null;
   if ( arguments.length < 3 ) {
         return false;
   } this.xmlDoc = ( function() {
      try {
         if ( check ) {
            this.xml = new XMLHttpRequest();
         } else {
            try {
            var client = [ "MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP" ];
            for ( var i = 0; i < client.length; ++i ) {
               if ( new ActiveXObject( client[ i ] )) {
                  this.xml = new ActiveXObject( client[ i ] );
                  break;
               }
            }
            } catch( e ) {
               this.xml = 0;
            }
         }
      } catch( er ) {
         if ( "createRequest" in window ) 
            this.xml = createRequest();
         else
            this.xml = 0;
      } return (( this.xml ) ? this.xml : 0 );
   } )();
   if ( this.xmlDoc ) {
      this.createRequest = ( function( xhr, callback, url, method ) {
         (( "overrideMimeType" in xhr ) ? xhr.overrideMimeType("text/xml") : xhr );
         xhr.onreadystatechange = callback;
         xhr.open( method, encodeURI( url ), true );
         (( method === "POST" && "setRequestHeader" in xhr ) ? xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8;") : xhr );
         xhr.send((( method === "POST" ) ? " " : null )); 
      } )( this.xmlDoc, this.callback, this.url, this.method );
   } return this.createRequest;
}; onload = function() {
new XHR( "GET", "your[b]XML[/b]path", leValorXML );

// You can create a new instance of request by calling out, the same procedure above. 
};

// ECMAScript v1.5 -->
</script>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.