Generate XML data dynamically in Flex.

We may have a requirement were we wanted to generate XML data to send through Httpservice or create a XML page with it.

Then here to get that XML type data we could use a little bit of ActionScript code like below.

Here iam using XML Class and XMLList Class.

First iam defining my RootNode of type XML and then node name and node value of Type String and Then create a XMLList using this node name and node value,and then append this to XML RootNode using the method appendChild().Thats it ur XML data is created, now we can extend this to generate any number of XML lines type data.

Code Example:

private function createXML(): void
{
var xm:XML = <Relyon></Relyon>;
var nodeName:String = “EMPLOYEENAME”;
var nodeValue:String = “KUMAR”;
var xmlList:XMLList = XMLList(”<”+nodeName+”>”+nodeValue+”</”+nodeName+”>”);
xm.appendChild(xmlList);
Alert.show(xm);
}

This will do the JOB. Leave any comments for queries.

2 Responses to “Generate XML data dynamically in Flex.”

  1. Meena Says:

    Hi Kumar,

    Thanks for the info,
    how can I generate XML like this:

    Thanks for any help.

  2. kumargandhi Says:

    Hello Meena,

    For this we got to use the some classes in flash.xml package, i can give another example for you.

    [Bindable]
    public var xml:XML

    private function createXML():void

    {
    try
    {
    xml =

    {content.text}
    ;
    }
    catch (e:TypeError)

    {
    xml = Fill the form to see the tag here.;
    }

    }

    by this also we can generate dynamic xml data,By using XML class.
    here tagName , attributeName are my TextInput Components.

    regards,
    kumar.

Leave a Reply