I am creating a XMl like this
var xml123:XML = <root></root>;
xml123.appendChild(<node uri='${urlValues[0]}' ></node>);
xml123.child("node").appendChild(<row></row>);
xml123.child("node").child("row").appendChild(<item>item01</item>);
xml123.child("node").child("row").appendChild(<item>item02</item>);
xml123.child("node").appendChild(<row></row>);
xml123.child("node").row[1].appendChild(<item>item03</item>);
xml123.child("node").row[1].appendChild(<item>item04</item>);
Now i want to add a url value dynamically so i used this code <node uri='${urlValues[0]}' ></node>
but its not working and i cant give <node uri=${urlValues[0]} ></node>
is their any way so uri value can be take from a different variable ?
Value i am getting like this
var urlValues:Array ;
urlValues = userSelected.split("@");
CodePudding user response:
The variable format is explained here. So you don't need to construct XML with lots of code, you just need to mention variables in its body:
var X:XML =
<root>
<FirstElement>
First
</FirstElement>
<SecondElement SecondAtt={urlValues[0]}>
Second
</SecondElement>
</root>
If that doesn't work, you may assign the data to a local variable that SHOULD work:
var uv0:String = urlValues[0];
var X:XML =
<root>
<FirstElement>
First
</FirstElement>
<SecondElement SecondAtt={uv0}>
Second
</SecondElement>
</root>
CodePudding user response:
Ok at last i found how it can be achieve ,may be multiple solution but one solution which can do the work
var xml123 = new XML("<root></root>");
xml123.FirstElement = "First";
xml123.SecondElement = "Second";
xml123.SecondElement.@SecondAtt = urlValues[0]; // <- I know what value to input
So it will genrate the xml like this
<root>
<FirstElement>
First
</FirstElement>
<SecondElement SecondAtt="http://2.4.5.6:1000">
Second
</SecondElement>
</root>
So it will serve the purpose and i can easily add attribute dynamically. But issue with this method lots of code i have to write to generate the xml.