# How to create XML from Flash?

**URL:** <https://forum.kirupa.com/t/how-to-create-xml-from-flash/25128>\
**Category:** Uncategorized\
**Created:** [July 9, 2003, 6:11pm UTC](https://forum.kirupa.com/t/how-to-create-xml-from-flash/25128 "2003-07-09T18:11:40Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![SX1Dude](https://avatars.discourse-cdn.com/v4/letter/s/85f322/32.png) [@SX1Dude](https://forum.kirupa.com/u/SX1Dude)\
**Post date:** [July 9, 2003, 6:11pm UTC](https://forum.kirupa.com/t/how-to-create-xml-from-flash/25128/1 "2003-07-09T18:11:40Z")

</div>

I know you can import an XML file to supply Flash with data but is it possible to create an XML file from data held in variable/ array in Flash to be saved locally or on a web server ?

If so how would one do such a thing…how are the nodes and children created etc ?

:thumb:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 9, 2003, 6:24pm UTC](https://forum.kirupa.com/t/how-to-create-xml-from-flash/25128/2 "2003-07-09T18:24:49Z")

</div>

i believe you can construct the xml, however, saving it would be an issue. I’m really not sure if you can save date into a file from flash… But… i believe you can use a server, and send the text to the server where an PHP or an [ASP.Net](http://ASP.Net) or ASP app could save that data…  
I’d have to look into it more. =) im intrigued.

in the meantime, you can look at this.

[http://www.kirupa.com/developer/actionscript/xmlfromflash.htm](http://www.kirupa.com/developer/actionscript/xmlfromflash.htm)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 9, 2003, 6:38pm UTC](https://forum.kirupa.com/t/how-to-create-xml-from-flash/25128/3 "2003-07-09T18:38:45Z")

</div>

I see what you mean…If I were for example to create from scratch many records in an array consisting of the following field/variables:

Name  
Address  
Age  
Phone  
Interests

How would I create the structured XML file ?..I wonder if senocular could help on this one given that he wrote the tutorial.

I know you can load XML from a local file or web server…I do not want to load as I have the data in flash I want to create and save an xml file locally or to a web server.

This would be really useful for others I am sure…senocular are you around ???

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 9, 2003, 7:06pm UTC](https://forum.kirupa.com/t/how-to-create-xml-from-flash/25128/4 "2003-07-09T19:06:12Z")

</div>

well you would create the XML inflash, and there are methods that support that, and then you send that object or text (whatever it is…) to a webserver in which you’d have a web application running waiting to accept that file and write it out and save it.

I could make an example for you tonight, hopefully be done by tomarrow =)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 9, 2003, 7:38pm UTC](https://forum.kirupa.com/t/how-to-create-xml-from-flash/25128/5 "2003-07-09T19:38:51Z")

</div>

I welcome your ethusiasm thanks…so what you are saying for example is :

[AS]function person(name, address, tel, interest) {  
this.name = name;  
this.address = address;  
this.tel = tel;  
this.interest = interest;  
}[/AS]

[AS]people = [];  
people.push(new person(“somebody”,“right here”,12345678,“drinking”));  
people.push(new person(“somebody2”,“right here2”,00000000,“drinking & dancing”));[/AS]

This array somehow gets turned into:

```php
<people>
      <person>
            <name>somebody</name>
            <address>right here</address>
            <tel>12345678</tel>
            <interests>drinking</interests>
      </person>
      <person>
            <name>somebody2</name>
            <address>right here2</address>
            <tel>00000000</tel>
            <interests>drinking & dancing</interests>
      </person>
</people>

I know this is not PHP but how do I post XML tags in this forum ????

```

How would the array get turned in the XML structure as above ??..

Could the xml above then be saved into a text file but with an .xml extension ???

I also need the chioce to save this locally or to a web sever for retrieval at a later date.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 9, 2003, 9:59pm UTC](https://forum.kirupa.com/t/how-to-create-xml-from-flash/25128/6 "2003-07-09T21:59:37Z")

</div>

well to save thats what the web application (not flash) would be responsible for. (Im an [ASP.net](http://ASP.net) guy btw)

you’d do something like this… (this is just an example, i havent checked for errors etc)…

(taken from [http://www.kirupa.com/developer/actionscript/xmlinflash.htm](http://www.kirupa.com/developer/actionscript/xmlinflash.htm))

{Edited:}  
im working on a demo for ya…  
take a look at this…  
Sen is the man =)

[http://www.kirupa.com/developer/actionscript/create\_edit\_xml.htm](http://www.kirupa.com/developer/actionscript/create_edit_xml.htm)

thats the idea, then you’d take the object and send that somehow =)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 10, 2003, 1:07am UTC](https://forum.kirupa.com/t/how-to-create-xml-from-flash/25128/7 "2003-07-10T01:07:55Z")

</div>

hold on thats not totally correct, lemme fix it…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 10, 2003, 2:50am UTC](https://forum.kirupa.com/t/how-to-create-xml-from-flash/25128/8 "2003-07-10T02:50:46Z")

</div>

ok i got it creating the xml correctly… heres what i have…

```php

function person(name, address, tel, interest) {
        this.name = name;
        this.address = address;
        this.tel = tel;
        this.interest = interest;
}

people = [];
people.push(new person("somebody","right here",12345678,"drinking"));
people.push(new person("somebody2","right here2",00000000,"drinking & dancing"));

my_xml = new XML("<people />");

for(i=0;i < people.length;i++)
{
	my_xml.childNodes[0].appendChild(my_xml.createElement("person"));
	my_xml.childNodes[0].childNodes*.appendChild(my_xml.createElement("name"));
	my_xml.childNodes[0].childNodes*.childNodes[0].appendChild(my_xml.createTextNode(people*.name));
	my_xml.childNodes[0].childNodes*.appendChild(my_xml.createElement("address"));
	my_xml.childNodes[0].childNodes*.childNodes[1].appendChild(my_xml.createTextNode(people*.address));
	my_xml.childNodes[0].childNodes*.appendChild(my_xml.createElement("tel"));
	my_xml.childNodes[0].childNodes*.childNodes[2].appendChild(my_xml.createTextNode(people*.tel));
	my_xml.childNodes[0].childNodes*.appendChild(my_xml.createElement("interest"));
	my_xml.childNodes[0].childNodes*.childNodes[3].appendChild(my_xml.createTextNode(people*.interest));
}

trace(my_xml.toString());

```

it puts the xml in one line but its well formed =)

and no matter how many items you add to the people array it’ll still write out the entry for every person.

im working on the “saving” part… that will be an [ASP.net](http://ASP.net) web app. Not sure what server side programming you’re going to use, but i’ll try to help .

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 10, 2003, 2:11pm UTC](https://forum.kirupa.com/t/how-to-create-xml-from-flash/25128/9 "2003-07-10T14:11:28Z")

</div>

You say you got the XML now albeit on one line, brilliant !!!

Wonder if there is a way to nest the xml code ???

But now SURELY !!! using the loadvars() thingy it would be possible to save it to a text file locally with the extension .xml ie people.xml ???

Given that Sen and I share the same birthday 27th September :toad:…I think he should get involved at some point to help out.

Could you attach the .FLA

Bye for now…

:phil:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 10, 2003, 2:37pm UTC](https://forum.kirupa.com/t/how-to-create-xml-from-flash/25128/10 "2003-07-10T14:37:11Z")

</div>

hehe

yea i’ll attach the FLA tonight. (but thats code is all there is =) )

what i did was use the Xml.Send(“url.aspx”) and it sends it using the post method, and from there i can take the info and write a file. =)

what server side scripting are you using?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 10, 2003, 7:47pm UTC](https://forum.kirupa.com/t/how-to-create-xml-from-flash/25128/11 "2003-07-10T19:47:40Z")

</div>

I would be using PHP for storage of the XML file on a webserver but also want to store it on the c:\ locally.

What about this example to save locally:

[AS]  
on (release) {  
var1 = “some text here”;  
var2 = “some text here 2”;  
var3 = “some text here 3”;  
fscommand (“save”, “example.xml”);  
}  
[/AS]

Obviously would need xml structure…

🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 10, 2003, 8:17pm UTC](https://forum.kirupa.com/t/how-to-create-xml-from-flash/25128/12 "2003-07-10T20:17:47Z")

</div>

The FSCommand save only works with projector files and would need a c++, java, vb program to accept variables to create an XML file…bummer!!!

BUT how about sharedobject…YES !!!

[http://www.kirupa.com/developer/mx/sharedobjects.htm](http://www.kirupa.com/developer/mx/sharedobjects.htm)

Now in theory I do not need to put data in an XML file format and save locally then retrieve at another time.

We could put the data in the shared object and then save it locally…with a load button to read the data from the shared object ???

What about this example:

A .swf contains a circle which starts at x,y 100,100 and three buttons, save, load and clear.

The circle is dragged to x,y 200,200 and then when save button is clicked that the circle and new co-ordinates are saved ie 200,200.

The clear button is clicked which starts the .swf from the first frame.

Then the load button is clicked which loads the shared object containing the circle and 200,200. ie the last position the circle was in.

Do you think this would work ???

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 11, 2003, 4:21am UTC](https://forum.kirupa.com/t/how-to-create-xml-from-flash/25128/13 "2003-07-11T04:21:22Z")

</div>

well php has functionality (or should ) to write files locally. What you’ll neeed to do is “send” the data to a page, that page will read the variable (using the post method) and then you’ll take that string of text and output it to a local file.

Its been a long time i used php…

you’re on the right track though =)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 11, 2003, 4:49pm UTC](https://forum.kirupa.com/t/how-to-create-xml-from-flash/25128/14 "2003-07-11T16:49:14Z")

</div>

Did you say you were going to try something with PHP ??

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 12, 2003, 10:39pm UTC](https://forum.kirupa.com/t/how-to-create-xml-from-flash/25128/15 "2003-07-12T22:39:40Z")

</div>

I could…

Let me see what i can do, im pretty busy as it is =) (stupid project at work)…

anyway, i’ll see what i can do for ya =)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 13, 2003, 7:51am UTC](https://forum.kirupa.com/t/how-to-create-xml-from-flash/25128/16 "2003-07-13T07:51:13Z")

</div>

Sounds great…priorities first though…I am doing some work with Ahmed at the moment this may have an impact on the XML thing.

Take it easy…
