11 Replies Latest reply on Sep 28, 2006 8:03 AM by Smart2k

    Writing into XML File in Flex

    Smart2k
      Hi,

      I want to create a XML file (dynamically) and writes data into that xml file(data coming from web service).

      Thanks in advance.

        • 1. Re: Writing into XML File in Flex
          peterent Level 2
          When you say "create a XML file" do you mean you want the Flex application to write a file onto the user's local disk? If so, that's not possible.

          If you mean you want to create an XML document in memory and send it off to a web service, then try this:

          var newdata:XML = <rootTag />;

          now you can add nodes: newdata.person.firstName = "Bill"; newdata.person.lastName = "Smith" and this produces:

          <rootTag>
          <firstName>Bill</firstName>
          <lastName>Smith</lastName>
          </rootTag>

          I'm using the E4X syntax. Check that out.

          You can also do:

          var newxml:String = "<rootTag><firstName>"+firstName.text+"</firstName><lastName>"+lastName.text+"</lastName> </rootTag>";

          and either convert it into XML: var realxml:XML = new XML(newxml); or just send the string back.
          • 2. Re: Writing into XML File in Flex
            14bizz
            I would like to "create and update a XML file" in the user local disk through a Flex application that would work stand-alone. Later, the xml file would be uploaded to the server. If this is not possible, this a good opportunity for improvment in future Flex versions.
            What I will try is to create a local web service. Let´s see if it will work? Any other suggestion?
            Thanks
            • 3. Re: Writing into XML File in Flex
              ntsiii Level 3
              There are available "projectors" that allow you to run a swf in an environment that does not have the security restrictions that the browser-based player has. These allow you to write to the local file system.

              Tracy
              • 4. Re: Writing into XML File in Flex
                Smart2k Level 1
                Thank you. I got it.
                • 5. Re: Writing into XML File in Flex
                  Smart2k Level 1
                  i want to write the data(coming from web service) into XML file and keep that XML file in Cache,then read that XML file contents and post into UI Control(Datagrid).

                  <b>Sample Output Data from my Webservice:</b>
                  <CoreProgramming>
                  <BasicProgramming>
                  <ProductId>10049</ProductId>
                  <ProgrammingName>America'sTop60</ProgrammingName>
                  <Price>29.99</Price>
                  <IncludesLocals>false</IncludesLocals>
                  <IncludesRSN>false</IncludesRSN>
                  <Listing>
                  <CategoryName>WOMEN'SPROG</CategoryName>
                  <Station>
                  <StationCallLetters>TLC</StationCallLetters>
                  <Hdflag>false</Hdflag>
                  </Station>
                  <Station>
                  </Listing>
                  </BasicProgramming>

                  <BasicProgramming>
                  <ProductId>10041</ProductId>
                  <ProgrammingName>America'sTop120</ProgrammingName>
                  <Price>39.99</Price>
                  <IncludesLocals>false</IncludesLocals>
                  <IncludesRSN>true</IncludesRSN>
                  <Listing>
                  <CategoryName>WOMEN'SPROG</CategoryName>
                  <Station>
                  <StationCallLetters>TLC</StationCallLetters>
                  <Hdflag>false</Hdflag>
                  </Station>
                  <Station>
                  <StationCallLetters>DHLTH</StationCallLetters>
                  <Hdflag>false</Hdflag>
                  </Station>
                  <Station>
                  <StationCallLetters>DISC</StationCallLetters>
                  <Hdflag>false</Hdflag>
                  </Station>
                  </Listing>
                  </BasicProgramming>

                  <BasicProgramming>
                  <ProductId>10045</ProductId>
                  <ProgrammingName>America'sTop180</ProgrammingName>
                  <Price>49.99</Price>
                  <IncludesLocals>false</IncludesLocals>
                  <IncludesRSN>true</IncludesRSN>
                  <Listing>
                  <CategoryName>WOMEN'SPROG</CategoryName>
                  <Station>
                  <StationCallLetters>TLC</StationCallLetters>
                  <Hdflag>false</Hdflag>
                  </Station>
                  <Station>
                  <StationCallLetters>DIY</StationCallLetters>
                  <Hdflag>false</Hdflag>
                  </Station>
                  <Station>
                  <StationCallLetters>LIME</StationCallLetters>
                  <Hdflag>false</Hdflag>
                  </Station>
                  </Listing>
                  </BasicProgramming>



                  </CoreProgramming>


                  • 6. Re: Writing into XML File in Flex
                    thatadbobestephen
                    I am interested in providing client-side persistence when the client is disconnected but generally share data with a serrver-side app. I had considedered writing to local XML files. but when I set up the Flex 2 compiler to compile with the option with -use-network=false I am then not able to get the server's data surely.

                    Is it possible to just use the dataservice component .

                    I am not clear from the documentation for the DataService component when it says "You can call the DataService.disconnect() method to force a connected client to disconnect; in this case, the DataService component keeps a copy of its managed data and automatically resubscribes to pick up changes when you reconnect." Does that mean that it will reconnect automatically after an application has been closed and re-opened and indeed the client PC shut down and restarted, and sync the data?

                    • 7. Re: Writing into XML File in Flex
                      ntsiii Level 3
                      Smart2k ,
                      When you say "..keep that XML file in Cache..." exactly what do you mean? What is the use-case, or what are you trying to achieve?

                      Tracy
                      • 8. Re: Writing into XML File in Flex
                        ntsiii Level 3
                        thatadbobestephen,
                        Are you talking about FDS (Flex Data Services)?

                        I am not familiar with FDS yet.

                        While you cannot write to the local file system, you can persist data using Local Shared Objects. LSOs are like "cookies on steroids."

                        Tracy
                        • 9. Re: Writing into XML File in Flex
                          Smart2k Level 1
                          Thanks for your reply.
                          I want to write the data coming from web service method into XML file. Then read the data from XML file and post into UI Control (Data grid).

                          I don’t want to hit WSDL every time by each request. For every day, when the first time hitting to WSDL and writes response into XML file, after that for each request handled by XML file instead of hitting WSDL. So I want to keep that XML file in Cache and set the logic for refresh every 24 hours.

                          Could you please give some solutions on it.

                          Thanks
                          • 10. Re: Writing into XML File in Flex
                            peterent Level 2
                            When you retrieve the information from the WebService you are probably receiving it into a Flex variable, such as an XMLListCollection. That collection remains in memory while that Flash Player instance (running the Flex app) is alive. So any time during that session you should be able to go into that variable and get the information you require.

                            The Flash Player cannot write files to disk (when launched from a browser). Your best hope of keeping that data between sessions would be to use a local SharedObject - much like a cookie. But the end-user can turn off the ability to save that or just restrict the size of the data that can be saved.

                            If you use a local SharedObject then you have to anticipate that possibility and allow your application to retrieve the XML data from the WebService each time it starts up.
                            • 11. Re: Writing into XML File in Flex
                              Smart2k Level 1
                              Thank You. I will