Solved

Rebuild XML data

Posted on 2004-10-10
6
192 Views
Last Modified: 2010-04-03
Hi,

I am reading a XML file into Flash.

Creating Arrays from the Data.

Then, I am modifying these arrays.

And then, I want to recreate the XML again which will be sent to a server side script to update the origional XML on the server.

Can anyone suggest how to i do this? I dont know how to recreate the XML after the Arrays have been modified.
Any suggestion is welcome.

thanks.
0
Comment
Question by:ssdesign
  • 3
  • 2
6 Comments
 
LVL 27

Accepted Solution

by:
negatyve earned 300 total points
ID: 12270203
ok, follow me:

• create a new xml file, named "test.xml"
• write inside it:

<?xml version="1.0" encoding="UTF-8" ?>
<data>
      <item>10</item>
      <item>45</item>
      <item>12</item>
      <item>34</item>
</data>

• create a flash movie in the same folder
• test this code:

data_xml = new XML();
data_xml.ignoreWhite = true;
data_xml.onLoad = function(success)
{
      if(success){
            // edit xml file
            editXML(this);
      } else {
            // xml file missing
            trace("XML FILE NOT FOUND");
      }
};
function editXML(xml)
{
      // show source xml file in the output windo
      trace(xml);
      // create an empty array
      var temp_array = new Array();
      // select the items node sequence in the xml file
      var nodes = xml.firstChild.childNodes;
      for(var i = 0; i < nodes.length; i++){
            // push inside the array the numeric value of each item
            temp_array.push(Number(nodes[i].firstChild.nodeValue));
      }
      // show in the output window the filled array
      trace(temp_array);
      // add a value to each element (modify)
      for(var i = 0; i < temp_array.length; i++){
            temp_array[i] = temp_array[i] * 2;
      }
      // show in the output window the modified array
      trace(temp_array);
      // create the new xml
      var new_xml = new XML('<?xml version="1.0" encoding="UTF-8" ?><data></data>');
      // add nodes
      for(var i = 0; i < temp_array.length; i++){
            // create the node
            var new_node = new_xml.createElement("item");
            // append inside it the corresponding array element as text
            new_node.appendChild(new_xml.createTextNode(temp_array[i]));
            // insert it in the new xml
            new_xml.firstChild.appendChild(new_node)
      }
      // trace the new xml
      trace(new_xml)
}
data_xml.load("test.xml");
0
 
LVL 7

Author Comment

by:ssdesign
ID: 12284401
ok thats looks quiet ok, i will need to try it.

I will get back soon with my feedback wether it worked or not.

Just need to try it with my application.
0
 
LVL 27

Expert Comment

by:negatyve
ID: 12295537
That's ok, take your time.. :)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 7

Author Comment

by:ssdesign
ID: 12320910
I have not forgotten, give me just one more day. Ok?
0
 
LVL 27

Expert Comment

by:negatyve
ID: 12346439
>I have not forgotten, give me just one more day. Ok?

hehe, that's right, no worries...
0
 

Expert Comment

by:subhailc
ID: 12472116
i know this is closed and all but that was a great answer.  to the original poster: feel lucky :D  information like that can be (is) expensive and rare.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Can't get text from a text entry 13 276
playing flash video on kiosk at startup 6 406
private function works only without TabNavigator? 3 301
embedding a media live encoder stream 3 119
I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now