ArrayCollection to XML Conversion

This post have three significant solutions:

   1. ArrayCollection output into XML
   2. Converting any MySQL DB values into XML using PHP
   3. Simple Login form using PHP and MXML

The below php code converts db output as xml dbtoconnect.php



$result = mysql_query(“SELECT * FROM “.TABLE_NAME);//Get the number of rows
$num_row = mysql_num_rows($result);
echo ‘<?xml version=”1.0″ encoding=”iso-8859-1”?>’;//Start the output of XML
echo “<data>”;
echo ‘<num>’ .$num_row. ‘</num>’;
if (!$result) {
die(‘Query failed: ‘ . mysql_error());
/* get column metadata – column name */
 $i = 0;
 while ($i < mysql_num_fields($result)) {
    $meta = mysql_fetch_field($result, $i);
  $ColumnNames[] = $meta->name;  //place col name into array
$specialchar = array(“&”,”>”,”<“);  //special characters
$specialcharReplace = array(“&amp;”,”&gt;”,”&lt;”); //replacement
/* query & convert table data and column names to xml*/

$w = 0;
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo “<row>”;
foreach ($line as $col_value){
 echo ‘<‘.$ColumnNames[$w].’>’;
 $col_value_strip = str_replace($specialchar, $specialcharReplace, $col_value);
 echo $col_value_strip;
 echo ‘</’.$ColumnNames[$w].’>’;
 if($w == ($i – 1)) { $w = 0; }
 else { $w++; }
echo “</row>”;
echo “</data>”;


The below mxml file converts php ArrayCollection output into XML dbconnect.mxml

 <?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”” layout=”absolute” horizontalAlign=”center” verticalAlign=”middle” creationComplete=”init()”>
 <mx:Style source=”css/halo.css”/>
   import mx.controls.Alert;
   import mx.collections.ArrayCollection;
   public var xmlList:XMLList;
   public var userBoolean:Boolean;
   public var passBoolean:Boolean;
   private function init():void
   public function remoteloginValidation(event:ResultEvent):void
    xmlList = xmlConvertion(;
    //“remoteloginValidation :”+xmlList);

   public function remoteLoginFaultHandler(event:FaultEvent):void
   {, ‘Error’);
   private function xmlConvertion(xmlArrayCol:ArrayCollection):XMLList
    var xmlString:String = “<?xml version=\”1.0\” encoding=\”utf-8\”?>\n<data>”;
    for each(var xmlObj:Object in xmlArrayCol)
     xmlString += “<record>”;
     xmlString += “<UserId>”+xmlObj.UserId+”</UserId>”;
     xmlString += “<Loginname>”+xmlObj.Loginname+”</Loginname>”;
     xmlString += “<Password>”+xmlObj.Password+”</Password>”;
     xmlString += “</record>”;
    xmlString += “\n</data>”;
    return new XMLList(xmlString);
   private function loginHalo(event:Event):void
    var _userName:String = userNameText.text;
    var _passName:String = passNameText.text;
    var xmlListValidation:XMLList = xmlList.record.(Loginname == _userName)
    //“loginHalo :”+xmlListValidation.Loginname);
    userBoolean = String(xmlListValidation.Loginname)==_userName;
    passBoolean = String(xmlListValidation.Password)==_passName;“userBoolean :”+userBoolean+” , passBoolean :”+passBoolean);
    if((!userBoolean) && (!passBoolean))
    {“UserName & Password Wrong”);
    else if((userBoolean) && (!passBoolean))
    {“Password Wrong”);
   private function forgetPass(event:Event):void

 <mx:HTTPService id=”httpserviceId” url=”http://localhost/dptoconnect.php” useProxy=”false” showBusyCursor=”true” result=”remoteloginValidation(event)” fault=”remoteLoginFaultHandler(event)”/>   
 <mx:Panel id=”panelId” width=”420″ height=”220″> 
  <mx:VBox width=”100%” height=”70%” backgroundColor=”#E0E0E0″ horizontalGap=”0″ verticalGap=”0″>
   <mx:Form id=”loginForm” textAlign=”left”>   
    <mx:FormItem label=”User Name:”>
              <mx:TextInput id=”userNameText” />
          <mx:FormItem label=”Password:”>
              <mx:TextInput id=”passNameText” displayAsPassword=”true”  />
              <mx:CheckBox label=”Always login me with current credential”/>
           <mx:FormItem width=”60″>
               <mx:Button id=”loginId” label=”LOGIN” styleName=”LoginButton” click=”loginHalo(event)” />
           <mx:FormItem >
               <mx:LinkButton label=”I forget my password” rollOverColor=”#EFE9D9″ click=”forgetPass(event)”/>
  <mx:HBox width=”100%” height=”30%” verticalGap=”0″ horizontalGap=”0″ backgroundColor=”#F0F0F0″ verticalAlign=”middle” borderColor=”#BABABA”>
   <mx:VBox width=”100%” horizontalAlign=”center” verticalAlign=”middle” borderColor=”#BABABA” verticalGap=”0″>
    <mx:HBox width=”100%” horizontalAlign=”center”>
     <mx:Label text=”Problems with the application?” fontSize=”12″/>
     <mx:LinkButton label=”” textDecoration=”underline” color=”#AE2324″ selectionColor=”#BFBFBF” rollOverColor=”#F0F0F0″/>
    <mx:HBox width=”100%” horizontalAlign=”center”>
     <mx:LinkButton label=’Copyright @ 2008, Emantras Inc.’ textDecoration=”underline” color=”#AE2324″ selectionColor=”#BFBFBF” rollOverColor=”#F0F0F0″ />


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: