We help IT Professionals succeed at work.

Get Node Values from SharePoint List

Christopher Gore
Christopher Gore used Ask the Experts™
I was show how to access the responsXML once for my list.  I am trying figure out how to get to the nodes again.  The last time I did it, it was with Chrome Developer tools in the browser.

I have a function like this:

function myFunction(responseXML) {
		var itemList = [];
		for (var i = 0; i < responseXML.getElementsByTagName("entry").length; i++) {
			id = responseXML.getElementsByTagName("entry")[i].childNodes[0].childNodes[0].nodeValue;
			title = responseXML.getElementsByTagName("entry")[i].childNodes[20].childNodes[0].childNodes[5].childNodes[0].nodeValue;
			header = responseXML.getElementsByTagName("entry")[i].childNodes[20].childNodes[0].childNodes[7].childNodes[0].nodeValue;
			urlDescription = responseXML.getElementsByTagName("entry")[i].childNodes[20].childNodes[0].childNodes[8].childNodes[0].childNodes[0].nodeValue;
			url = responseXML.getElementsByTagName("entry")[i].childNodes[20].childNodes[0].childNodes[8].childNodes[1].childNodes[0].nodeValue;
			methodType = responseXML.getElementsByTagName("entry")[i].childNodes[20].childNodes[0].childNodes[9].childNodes[0].nodeValue;
			itemList.push(new Item(id, header, title, url, urlDescription, methodType));

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi Chris
It would be very helpful if you share value of 'responseXML' you are referring.
if you are using jQuery also then you can use below samples:

var AllMemberNodes = $(xml).find('<NodeNameHere>');

Then you can loop like:

var allAttributes = AllMemberNodes[0].attributes.length;
for (var a = 0; a < allAttributes; a++)

Hope this logic helps you.
Systems architect
Top Expert 2006
even without jQuery you can make your code more readable like this:
function myFunction(responseXML) {
		var itemList = [];
		var entryNodes = responseXML.getElementsByTagName("entry");
		for (var i = 0; i < entryNodes.length; i++) {
			id = entryNodes[i].childNodes[0].childNodes[0].nodeValue;
			title = entryNodes[i].childNodes[20].childNodes[0].childNodes[5].childNodes[0].nodeValue;
			header = entryNodes[i].childNodes[20].childNodes[0].childNodes[7].childNodes[0].nodeValue;
			urlDescription = entryNodes[i].childNodes[20].childNodes[0].childNodes[8].childNodes[0].childNodes[0].nodeValue;
			url = entryNodes[i].childNodes[20].childNodes[0].childNodes[8].childNodes[1].childNodes[0].nodeValue;
			methodType = entryNodes[i].childNodes[20].childNodes[0].childNodes[9].childNodes[0].nodeValue;
			itemList.push(new Item(id, header, title, url, urlDescription, methodType));

Open in new window

...and even your subentries are better accessed by attributes then by index in the "entry" node. Show your XML text.