PDA

View Full Version : How to target an XML dynamicly?



ven
September 6th, 2007, 06:05 AM
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)

soulwire
September 6th, 2007, 06:50 AM
I'm confused!

Why do you need to put the employees back in after intentionally deleting them?

And your original XML is still intact after using the copy method, so you can manipulate, read it the same. I dont think I totaly understand the question.

ven
September 6th, 2007, 07:05 AM
The reason is that i use the XML as dataprovider for diffrent visualisations in Flex (like a Tree component), therefor copying it and manipulating it to fit the certain compoent. But still need to reach the original data in different clickActions in the components.