14 Replies Latest reply on Oct 25, 2010 8:16 PM by mroiler

    Flex Form To XML

    mroiler

      Hi,

      I need form data to be saved to the end of existing XML Document (I also need this done all locally.) I tried this but how do I make it save to the end of a XML document?

       

      var myXML:XML =

      <Person> 

      <First_Name>{nameFirst.text}</First_Name>

      <Last_Name>{nameLast.text}</Last_Name>

      <Address>{address.text}</Address>

      <Phone>{phone.text}</Phone>

      <City>{city.text}</City>

      <Email>{email.text}</Email>

      </Person>;

       

      What's Next?

        • 1. Re: Flex Form To XML
          mroiler Level 1

          Is there also a way for me to deny the app to put info in the xml file if i already have a set of it?

          • 2. Re: Flex Form To XML
            aktell2007 Level 1

            Hi there,

             

            http://tdotblog.info/?q=node/6

             

            regards aktell2007

            1 person found this helpful
            • 3. Re: Flex Form To XML
              mroiler Level 1

              Is there a way to have it automatically selected a xml file in the directory of the app? It's also giving me errors all over the place so i can't even launch it.

              • 4. Re: Flex Form To XML
                aktell2007 Level 1

                Sorry, but I dont understand what you are saying !


                • 5. Re: Flex Form To XML
                  mroiler Level 1

                  In that tutorial it had you select a file while running the app, right. Can I select the url in the code instead of the running app?

                  • 6. Re: Flex Form To XML
                    mroiler Level 1

                    I took a little bit of that code and got this:

                     

                    import mx.controls.Alert;

                    protected function submit_clickHandler(event:MouseEvent):void

                    {

                    var file:File = File.applicationDirectory;

                    file = file.resolvePath("data/data.xml");

                    var myXML:XML =

                    <Person> 

                    <First_Name>{nameFirst.text}</First_Name>

                    <Last_Name>{nameLast.text}</Last_Name>

                    <Address>{address.text}</Address>

                    <Phone>{phone.text}</Phone>

                    <City>{city.text}</City>

                    <Email>{email.text}</Email>

                    </Person>;

                    var fs:FileStream = new FileStream();

                    fs.open(file, FileMode.WRITE);

                    fs.writeUTFBytes(myXML);

                    fs.close();

                    Alert.show("Thank You! You have now been entered.","Thank You!");

                    }

                     

                    Before, with other sources I found on the web, the Alert at the bottom would always show and nothing had happened. When i did this after i clicked the button it never showed the alert. Its almost like its trying to do something.

                    • 7. Re: Flex Form To XML
                      aktell2007 Level 1

                      I'm not sure I just was looking at this a few days ago

                      if I could use it. There are some more or at lesat one more

                      article he wrote about it further to the bottom there was a link.

                       

                      regards aktell2007

                      • 8. Re: Flex Form To XML
                        mroiler Level 1

                        At the bottom of that article(the second one), it says:

                         

                        What this cold be used for:

                        • Saving program states to the
                          hard drive via AIR for later retrieval. An example of reading and writing
                          XML files can be found here.
                        • A quick way to save an object
                          to a database through a webservice for later use.
                        • A method to save data to an
                          AIR SQLLite DB.

                         

                        I'm using this to store data people typed in to this app and then i would reference the xml file later through Excel or something.

                        • 9. Re: Flex Form To XML
                          mroiler Level 1

                          Just tried the thing i did take a couple of lines from the code in the first blog and didn't run it off a installed app, i ran it right out of flash builder and got this:

                           

                           

                          SecurityError: fileWriteResource

                          at flash.filesystem::FileStream/open()

                          at TestForm2/submit_clickHandler()[(to my project)\src\TestForm2.mxml:30]

                          at TestForm2/__submit_click()[(to my project)\src\TestForm2.mxml:54]

                           

                          Line 30 is where it opens the file for writing, line 54 is the button.

                          • 10. Re: Flex Form To XML
                            aktell2007 Level 1

                            Well, sorry but I can't help you there I was looking into it awhile ago and did not pursue the idea.

                            I'm using only now databases and Php Xml DOM in transfer with FLEX information from customers this way I only have to write a new Php file to call up any information I need for what ever. That works perfectly well.

                            regards aktell2007
                            1 person found this helpful
                            • 11. Re: Flex Form To XML
                              mroiler Level 1

                              I could do PHP locally too i guess. Could you tell me how to do that for my situation? I know a little bit of PHP.

                              • 12. Re: Flex Form To XML
                                aktell2007 Level 1

                                Send me a E-mail through my account this needs a little m

                                ore time to do, and at the moment I'm at work !

                                My web site is down to dfind the Email address as I'm transfering to a new host so go through here !

                                • 13. Re: Flex Form To XML
                                  mroiler Level 1

                                  I think i figured out the problem! When i debug it says there is no source to write to. Am referencing the file correctly?

                                  • 14. Re: Flex Form To XML
                                    mroiler Level 1

                                    Finally! Here is my code!

                                     

                                    import mx.controls.Alert;

                                    protected function submit_clickHandler(event:MouseEvent):void

                                    {

                                    var file:File = File.desktopDirectory;

                                    file = file.resolvePath("data.xml");

                                    var myXML:XML =<Person><First_Name>{nameFirst.text}</First_Name><Last_Name>{nameLast.text}</Last_Name>< Address>{address.text}</Address><Phone>{phone.text}</Phone><City>{city.text}</City><Email> {email.text}</Email></Person>;

                                    var fs:FileStream = new FileStream();

                                    fs.open(file, FileMode.APPEND);

                                    fs.writeUTFBytes(myXML);

                                    fs.close();

                                    Alert.show("Thank You! You have now been entered.","Thank You!");

                                    }

                                     

                                    I put the xml on one line otherwise it gets confused at where i hit enter.