Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do I assign xml attributes

Posted on 2011-02-21
16
Medium Priority
?
867 Views
Last Modified: 2012-05-11
How do I set the quotes in my xml-string to create attributes.
In the example below the id in the brackets will simply show as is, not as the actual id-number.
newfile = <item id="{id}"><name>{xmlsetName}</name><age>{xmlAge}</age></item>;

Open in new window

How do I set the quotes correct.
Something like
<item id=+"{id}"+>

Open in new window

0
Comment
Question by:petersego
[X]
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
  • 8
  • 8
16 Comments
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34942408
newfile = "<item id='" + id + "'><name>" + xmlsetName + "</name><age>" + xmlAge + "</age></item>";

Warm Regards
Deepanjan Das
0
 

Author Comment

by:petersego
ID: 34942880
Thanks, but I would prefer to keep my syntax - not makiing it a string..
It works fine as long as I only use nodes and is going to be send through php.
What Im looking for is the right syntax """{id}"""
0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34943106
In Flash the bindlable {} will not work, its for Flex I guess.
Hence then try creating a XMLNode and using appendChild and adding attributes to the nodes.

Warm Regards
Deepanjan Das
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:petersego
ID: 34943244
Oh yes, it works. Originally I had the id in a node, and that worked flawlessly.
newfile = <item><id>{id}</id><name>{xmlsetName}</name><age>{xmlAge}</age></item>; 

Open in new window

but since I want to catch the corresponding nodes of the id, I assumed it would be better to place it in an attribute of the parentnode item.
What Im trying to do is to check if an id-number is in an xml-file. If it is, I want the corresponding name and age placed in each a dynamic textfield.
else I want to generate an id-number and place som input-textfields.
And thats where newfile is relevant.
My problem is that I cant get the if else work.
if the "id" doesnt exist, the else-part isnt executed.

0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34943300
That is really cool that you can use Bindable parenthesis {} in Flash, please may I know which version are you using in Flash IDE?
And can you share your code snippet of where you used the if else condition.

Warm Regards
Deepanjan Das
0
 

Author Comment

by:petersego
ID: 34943680
Well, Im still on CS4.
I might return with the if else problem. Something is definitively wrong...
But if you would check it, I'd be gratefull.
myXML = XML(myxmlLoader.data);
idLength=myXML.item;
for (var i:int; i < idLength.length(); i++ ) {
if (idLength[i].id==id){
nametxt.text=idLength[i].(id==id).name;
agetxt.text=idLength[i].(id==id).age;
}
else{
nametxt.text="Input your name";
agetxt.text="input your age";
}

Open in new window

and the xml
<?xml version='1.0' encoding='utf-8'?>
<items>
  <item>
    <id>106BB10495</id>
    <name>James</name>
    <age>65</age>
  </item>
  <item>
    <id>9915R72620</id>
    <name>Jerry</name>
    <age>87</age>
  </item>
  <item>
    <id>013R293445</id>
    <name>Jimmy</name>
    <age>22</age>
  </item>
</items>

Open in new window

0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34948290
In your comparison:
if (idLength[i].id==id)

Open in new window

where will the variable "id" come from?

Warm Regards
Deepanjan Das
0
 

Author Comment

by:petersego
ID: 34949057
id wil come from flashvars.
0
 

Author Comment

by:petersego
ID: 34949240
It seems that I cant iterate. If is only correct, if the correct id is placed first in the xml.
0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34949282
Try this:
myXML = XML(myxmlLoader.data);

nametxt.text="Input your name";
agetxt.text="input your age";

nametxt.text = myXML.item.(id == flashVarId).name;
agetxt.text = myXML.item.(id == flashVarId).age;

Open in new window


Warm Regards
Deepanjan Das
0
 

Author Comment

by:petersego
ID: 34949400
Ahh, okay, I dont have to iterate.
That helped on getting the correct id, nomatter where it was in the xml, but Im still having problems with the else part. If it isnt comparable to any id in the xml, nothing happens.

if(myXML.item.(id == flashVarId)){
nametxt.text = myXML.item.(id == flashVarId).name;
agetxt.text = myXML.item.(id == flashVarId).age;
}
else{
nametxt.text="Input your name";
agetxt.text="input your age";
}

Open in new window

if flashVarId doesnt exist in xml, nothing will show in the textfield.
0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34949429
If you use my script under ID:34949282, then you will not have to write the else part.
This is because, by default the values are set first, then the actual values are set based on id match.

So if the ids do not match nothing happens and the default values are set.

Warm Regards
Deepanjan Das
0
 

Author Comment

by:petersego
ID: 34949565
Well, in fact Im not only setting new values to the textfield, Im also changing the textfield to inputtype with borders and other input-features like eventlisteners
so in reality it will be looking like this:
var nametxt:TextField=new TextField();
var agetxt:TextField=new TextField();
inputTF();
valuesTF(); //This is if the FlashVarsId is present in the xml
addChild(nametxt);
addChild(agetxt);
which again results in that nothing happens if the FlashVarsId isnt present in the xml
function inputTF(){
	nametxt.x=100;
	nametxt.y=58;
    nametxt.width=190;
	nametxt.height=18;
    nametxt.border=true;
	nametxt.borderColor=0x666666;
	nametxt.selectable=true;
	nametxt.background=true;
	nametxt.type = TextFieldType.INPUT;
	nametxt.text="Input your name";
	nametxt.setTextFormat(preInputFormat);
	nametxt.addEventListener(Event.CHANGE,updatetext);
	nametxt.addEventListener(MouseEvent.CLICK,removeNameText);
	
	agetxt.x=100;
	agetxt.y=83;
	agetxt.width=190;
	agetxt.height=18;
	agetxt.border=true;
	agetxt.borderColor=0x666666;
    agetxt.selectable=true;
	agetxt.background=true;
	agetxt.type = TextFieldType.INPUT;
	agetxt.text="Input your age";
	agetxt.setTextFormat(preInputFormat);
	agetxt.addEventListener(Event.CHANGE,updatetext);
	agetxt.addEventListener(MouseEvent.CLICK,removeAgeText);
}

Open in new window

0
 
LVL 17

Accepted Solution

by:
deepanjandas earned 2000 total points
ID: 34949584
So what I understand is that if the id matches, you will change the type to dynamic - right?
then do this:
myXML = XML(myxmlLoader.data);

nametxt.type = TextFieldType.INPUT;
nametxt.text="Input your name";

agetxt.type = TextFieldType.INPUT;
agetxt.text="input your age";

var _name:String = myXML.item.(id == flashVarId).name;
var _age:String = myXML.item.(id == flashVarId).age;
if( _name ){
    nametxt.text = _name;
    nametxt.type = TextFieldType.DYNAMIC;
}
if( _age ){
    agetxt.text = _name;
    agetxt.type = TextFieldType.DYNAMIC;
}

Open in new window


Warm Regards
Deepanjan Das
0
 

Author Closing Comment

by:petersego
ID: 34950011
Thank you really much. I know that the question ended up far from the original, so I really appreciate it.
0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34950048
My Pleasure :)

Warm Regards
Deepanjan Das
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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 been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

609 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