Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Pass a Variable INTO Xml

Posted on 2010-09-07
3
391 Views
Last Modified: 2012-05-10
I have an ActionScript in Flash and an XML file that are working together.

I've set up my variables and such, and then I want to loop through them and add something to each "record." So I can do something like this:

for each (var object:XML in xml.*) {

                  object.appendChild(<myId>my id is here</myId>);
                  trace(object);
      }

That will add a new line in each item like so:
<myId>my id is here</myId>

Now, I obviously don't want to write "my id is here" as the value between the <myId> tags. The problem is I want to do something using a foruma or method or something to get a unique value there.

For example,  I'd like to do something like this...

object.appendChild(<myId>object.childIndex()</myId>);


...where the theory is that it returns the child index number of the object, so the fist item  would be appended with <myId>0</myId> and the second would be <myId>1</myId> and the third would be <myId>2</myId> and so on and so forth.

The problem is that it's writing everything as a string. It's actually writing out <myId>object.childIndex()</myId> for all of them,

I even tried doing something in ActionScript first, where I'd go:

var i;

and then push a value into the i variable via an incremental loop and then I would try

object.appendChild(<myId>i</myId>);

But, again, it just writes in "i" and not the value of i.

I need a way to say, "Calculate this part between the brackets."

Can anyone help? Is it possible? Is there another way around it?
0
Comment
Question by:caf210
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
ActionScript_Helper earned 500 total points
ID: 33624989
Here's an sample, it will append the new node. But see how we are concatenating string and variable.
---------------
var node:XMLList = new XMLList("<myId>" + i + "</myId>");
object.appendChild(node);

-------
0
 

Author Comment

by:caf210
ID: 33628622
ActionScript_Helper,

Yup, that's it. Exactly what I need.

Thank you much! I will accept as the solution and award the points.
0
 

Author Closing Comment

by:caf210
ID: 33628626
Great job.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

792 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