How to Access XML Attributes from Javascript

Dear all,

sorry if the question sounds naive, i want to know how to access the xml attributes from javascript. I am using dhtmlx ajax and i echo from php an xml string like:

<outcome1> good </outcome1> <outcome2> bad </outcome2>

on the javascript part, i have the code:

var loader = dhtmlxAjax.postSync("Php/logIn.php", encodeURI("uname=" + uname + "&pwd=" + pwd));       
	if (loader.xmlDoc.responseText == null)
	{    		
		alert("Response contains no Text");	
		return;
	}

Now i want to know how to read the attribute values of nodes outcome1 and outcome2

Thanks in advance!

Karvesh

Hi,

the xml is incorrect. The should be a top node. For example:

good
bad

Now i want to know how to read the attribute values of nodes outcome1 and outcome2

You may use doXPath. Something like so will return “good”:

var tags = loader.doXPath("//outcome1");
var value = tags[0].firstChild.data;

Please see XPath docs for more details (the issue doesn’t relate dhtmlxAjax).