# Get corresponding XML node after selecting?

**URL:** <https://forum.kirupa.com/t/get-corresponding-xml-node-after-selecting/24664>\
**Category:** flash\
**Created:** [July 3, 2003, 9:08am UTC](https://forum.kirupa.com/t/get-corresponding-xml-node-after-selecting/24664 "2003-07-03T09:08:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![keitai](https://avatars.discourse-cdn.com/v4/letter/k/73ab20/32.png) [@keitai](https://forum.kirupa.com/u/keitai)\
**Post date:** [July 3, 2003, 9:08am UTC](https://forum.kirupa.com/t/get-corresponding-xml-node-after-selecting/24664/1 "2003-07-03T09:08:31Z")

</div>

Hi there,

I am little bit stuck here. I got the following:

1 xml -file, like

```php

<?xml version="1.0" encoding="UTF-8"?>
<items>
  <item>Wyona Ryder</item>
  <item>Uma Thurman</item>
  <item>Tom Cruise</item>
<items>

```

2 i have succesfull parse the xml file in flash and got them in a pull-down menu.  
3 a user can select a name.

My problem: I can trace the chosen name, but i want the corresponding XML node as a var?  
That’s if the user selects Uma Thurman the corresponding XML node is 1, so how do i accomplish this?

I am trying to make a ‘getSelectXMLnode’ function, the parse function works properly

```auto

//parse xml file
function parseCelebs () {
if (_root.xmlDocument.loaded) {
for (var i = 0; i < _root.xmlDocument.childNodes.length; i++) {
if (_root.xmlDocument.childNodes*.nodeName == 'items') {
// _root.Celebs = this.childNodes*;
var cookieNodes = _root.xmlDocument.childNodes*.childNodes;
for (var j = 0; j < cookieNodes.length; j++) {
	if (cookieNodes[j].nodeName == 'item') {
	_root.Celebs[_root.Celebs.length] = cookieNodes[j].firstChild.nodeValue;
	_root.vips = cookieNodes[j].firstChild.nodeValue;
	//check if all celebs //trace (_root.vips);
					}
				}
				break;
			}
		}
		// trace (_root.Celebs.length);
		// we need # of celebs for the pull-down 
		noCelebs = _root.Celebs.length;
		_root.xmlDocument = null;
	}
}

function getSelectXMLnode () {
//for debug we use static value of 3 and tom cruise
for (var k = 0; k < 3; k++) {
 if (cookieNode[k].firstChild.nodeValue == 'tom cruise') {
	trace (k);
		}
	}

```

Thnks in advanced.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 3, 2003, 9:53am UTC](https://forum.kirupa.com/t/get-corresponding-xml-node-after-selecting/24664/2 "2003-07-03T09:53:08Z")

</div>

Hmm

I trigger the function by a button. I want the corresponding XML- node-array-number to be send as a variable. So in my function below it would be ‘k’.

This is what i have so far.

```auto

function getSelectCeleb () {
if (_root.xmlDocument.loaded) {
for (var k = 0; k < 3; k++) {
var cookieNodes = _root.xmlDocument.childNodes*.childNodes;
if (_root.XMLDocument.cookieNodes[k].firstChild.nodeValue == 'tom cruise') {	trace (k);
} }
} else {
trace ("Hum doesn't work");
}
}

```

I get the Hum doesn’t work, so somehow i can’t get to the XMLDocument.

Any suggestions,

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 3, 2003, 12:08pm UTC](https://forum.kirupa.com/t/get-corresponding-xml-node-after-selecting/24664/3 "2003-07-03T12:08:53Z")

</div>

This function just execute the else-statement not the if

```auto

function getSelectCeleb () {
	for (var j = 0; j < _root.xmlDocument.childNodes[0].childNodes.length; j++) {
		var cookieNodes = _root.xmlDocument.childNodes[0].childNodes;
		if (cookieNodes[j].firstChild.nodeValue == "Tom Cruise") {
			trace ("Array" + j + " = " + cookieNodes[j].firstChild.nodeValue);
		} else {
			trace ("Hum doesn't work");
			trace ("Help" + j + " = " + cookieNodes[j].firstChild.nodeValue);
		}
	}
}

```

Anyone??
