2 Replies Latest reply on Jan 12, 2011 9:01 AM by saisri2k2

    Create XML file

    capitainequebec

      I am using AIR and FileStream class to save file locally but I don"t know how to create XML file using AS. I think I should use something like this:

       

      var xmlPoincon:XML = new XML();

       

      But I don't know how to create the node of the XML and then the values.

       

      Regards,

      Daniel Cantin

       

       

       

        • 1. Re: Create XML file
          Gregory Lafrance Level 6

          Here is a simple code snippet:

           

          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);
          }
          

           

          Most important here is the appendChild() method, that allows you to add a node you have constructed.

           

          http://flexonblog.wordpress.com/2008/02/04/generate-xml-data-dynamically-in-flex/

           

          If this post answers your question or helps, please mark it as such. Thanks!

          http://www.stardustsystems.com
          Adobe Flex Development and Support Services

          • 2. Re: Create XML file
            saisri2k2 Level 4

            programmatically you can do the following

            var xmlPoincon:XML = new XML();
                           
                           protected function application1_creationCompleteHandler(event:FlexEvent):void
                           {
                                var root:XML = <root></root>; 
                                xmlPoincon.appendChild(root);
                                var firstElement:XML = <subElement>{"value"}</subElement>;
                                root.appendChild(firstElement);
                                xmlPoincon = root;
                                trace(xmlPoincon.toString());
                           }
            

             

            it will give

            <root>
              <subElement>value</subElement>
            </root>
            

             

             

            else you can give

             

            var xmlPoincon:XML = <root>
              <subElement>value</subElement>
            </root>;
            
            
            
            
            

             

            the above will work as well.

            1 person found this helpful