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 - 07 Sep 2007 19:01 GMT
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 - 18 Jul 2008 13:53 GMT
Thanks Tree Hugger!
From http://www.developmentnow.com/g/70_2007_9_0_0_1016254/Convert-XMLList-to-XML-in-
AS3.ht
Posted via DevelopmentNow.com Group
http://www.developmentnow.com
randygland - 25 Nov 2008 22:12 GMT
this helped me re-form filtered XML to set the dataProvider of the List component.
Cheers mate
From http://www.developmentnow.com/g/70_2008_7_0_0_1016254/Convert-XMLList-to-XML-in-
AS3.ht
Posted via DevelopmentNow.com Group
http://www.developmentnow.com/g/
Tim K - 25 Aug 2009 22:07 GMT
You could have also done this:
var newXML:XML = <your_root_tag/>
newXML.appendChild (yourXMLList);
Or even better, this works too:
var newXML:XML = <your_root_tag>{yourXMLList}</your_root_tag>;
From http://www.developmentnow.com/g/70_2008_11_0_0_1016254/Convert-XMLList-to-XML-in
-AS3.ht
Posted via DevelopmentNow.com Group
http://www.developmentnow.com/g/
Evan Gifford - 22 Oct 2009 22:48 GMT
One step simpler:
new XML( node.toXMLString() )
From http://www.developmentnow.com/g/70_2008_11_0_0_1016254/Convert-XMLList-to-XML-in
-AS3.ht
Posted via DevelopmentNow.com Group
http://www.developmentnow.com/g/
Veronica - 01 Dec 2009 23:20 GMT
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
http://www.developmentnow.com/g/