Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Convert XMLList to XML in AS3?

279 views
Skip to first unread message

TreeHugger98

unread,
Sep 6, 2007, 12:12:25 PM9/6/07
to
Hello,

I am trying to figure out how to convert an XMLList that I retreived from an
XML instance back into well-formed XML in Flash CS3. Here is what I am doing.
- I have an XML document loaded and I am displaying the contents in a datagrid
component (which is working well).
- I am then filtering the XML to obtain a subset of data by first obtaining an
XMLList representing all elements of my XML instance and then filtering the
list on a particular element (this is working well).
- Now I want to display my filtered results in the datagrid and here lies the
problem because the datagrid can't use an XMLList as a dataprovider. How do I
convert this XMLList back into well formed XML so I can use it as my grid's
dataprovider? I need to somehow get a root tag back on.

Could I somehow use toXMLString() and then convert that to XML?

Thank you in advance for any advice.

TH

TreeHugger98

unread,
Sep 7, 2007, 2:01:47 PM9/7/07
to
I solved this so I thought I would post how I did it in case anyone would find
this useful.

1. First, convert your XMLList to an xml string:

var yourXMLString:String = yourXMLList.toXMLString();

2. Next, add a root tag to the beginning and end of your xml string.

yourXMLString= "<your_root_tag>"+yourXMLString+"</your_root_tag>";

3. Convert the string to xml.

var yourNewXML:XML=new XML(yourXMLString);

yourNewXML is now well-formed xml and will work as a dataprovider.

TH

sixtyfootersdude

unread,
Jul 18, 2008, 8:53:59 AM7/18/08
to

randygland

unread,
Nov 25, 2008, 5:12:19 PM11/25/08
to
this helped me re-form filtered XML to set the dataProvider of the List component.

Cheers mate

:D

From http://www.developmentnow.com/g/70_2008_7_0_0_1016254/Convert-XMLList-to-XML-in-AS3.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com/g/

Tim K

unread,
Aug 25, 2009, 5:07:16 PM8/25/09
to
You could have also done this:

var newXML:XML = &lt;your_root_tag/&gt;

newXML.appendChild (yourXMLList);

Or even better, this works too:

var newXML:XML = &lt;your_root_tag&gt;{yourXMLList}&lt;/your_root_tag&gt;;


From http://www.developmentnow.com/g/70_2008_11_0_0_1016254/Convert-XMLList-to-XML-in-AS3.htm

Evan Gifford

unread,
Oct 22, 2009, 5:48:50 PM10/22/09
to
One step simpler:

new XML( node.toXMLString() );

Veronica

unread,
Dec 1, 2009, 6:20:58 PM12/1/09
to
Thank you so much. Very helpfull
Hope everybody completed their threads as you did.
Sometimes people don`t come up with an answer at the right time.
But when you keep working something comes up for sure.

Thank you again!!! ;D

From http://www.developmentnow.com/g/70_2009_8_0_0_1016254/Convert-XMLList-to-XML-in-AS3.htm

0 new messages