# How to target an XML dynamicly?

**URL:** https://forum.kirupa.com/t/how-to-target-an-xml-dynamicly/238010
**Category:** flash
**Created:** [September 6, 2007, 10:05am UTC](https://forum.kirupa.com/t/how-to-target-an-xml-dynamicly/238010 "2007-09-06T10:05:43Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![ven](https://avatars.discourse-cdn.com/v4/letter/v/f9ae1b/32.png) [@ven](https://forum.kirupa.com/u/ven)
#### Post date: [September 6, 2007, 10:05am UTC](https://forum.kirupa.com/t/how-to-target-an-xml-dynamicly/238010/1 "2007-09-06T10:05:43Z")

</div>

```php

private var myXML:XML = 
        <companies>
            <company name="Sun Inc.">
                <department name="Accounting">
                    <employee name="Paul"/>
                    <employee name="Jill"/>
                </department>
                <department name="Development">
                    <employee name="Ann"/>
                    <employee name="Peter"/>
                </department>
            </company>
            <company name="Moon Inc.">
                <department name="Accounting">
                    <employee name="Bill"/>
                    <employee name="Sam"/>
                </department>
                <department name="Development">
                    <employee name="Jenny"/>
                    <employee name="John"/>
                </department>
            </company>
        </companies>;

private var myNewXML:XML;

private function init():void {
    myNewXML = myXML.copy();
    delete myNewXML.company.department.employee;

    getContent(myNewXML.company[1].department[1]);
}

private function getContent(xml:XML):void {
    //get xml employees from myXML based on the xmlobject i get
}

```

Based on the position in myNewXML, how do I dynamicly get the content in the original myXML (I want to extract the employees from the myXML)?

I know I can get the position with xml.childIndex() and traverse through parents with xml.parent() but I dont know how I would write the syntax to actually target the original myXML.

(This code is simplified and cut down from a larger context, it may seem abit pointless in this context)
