Flash / Flex / ActionScript/XML/insert
Содержание
- 1 Add a new child to the end of the existing xml data
- 2 Adding a new child after all existing children
- 3 Adding a new child after a specific existing child
- 4 Adding a new child before a specific existing child
- 5 As an alternative to the insertChildAfter( ) approach (1)
- 6 As an alternative to the insertChildAfter( ) approach (2)
- 7 Use appendChild method to add new child to the end of existing xml data
Add a new child to the end of the existing xml data
package{
import flash.display.Sprite;
public class Main extends Sprite{
public function Main(){
var novel:XML = <BOOK ISBN="0000000000">
<TITLE>ActionScript</TITLE>
<AUTHOR>J, J</AUTHOR>
<PUBLISHER>Books Ltd</PUBLISHER>
</BOOK>
novel.*[novel.*.length( )-1] += <DESCRIPTION>A modern classic</DESCRIPTION>;
trace(novel);
}
}
}
Adding a new child after all existing children
package{
import flash.display.Sprite;
public class Main extends Sprite{
public function Main(){
var novel:XML = <BOOK ISBN="0000000000">
<TITLE>ActionScript</TITLE>
<AUTHOR>J, J</AUTHOR>
<PUBLISHER>Books Ltd</PUBLISHER>
</BOOK>
novel.insertChildAfter(novel.*[novel.*.length( )-1],
<DESCRIPTION>A modern classic</DESCRIPTION>);
trace(novel);
}
}
}
Adding a new child after a specific existing child
package{
import flash.display.Sprite;
public class Main extends Sprite{
public function Main(){
var novel:XML = <BOOK ISBN="0000000000">
<TITLE>ActionScript</TITLE>
<AUTHOR>J, J</AUTHOR>
<PUBLISHER>Books Ltd</PUBLISHER>
</BOOK>
novel.insertChildAfter(novel.AUTHOR[0], <AUTHOR>D, V</AUTHOR>);
trace(novel);
}
}
}
Adding a new child before a specific existing child
package{
import flash.display.Sprite;
public class Main extends Sprite{
public function Main(){
var novel:XML = <BOOK ISBN="0000000000">
<TITLE>ActionScript</TITLE>
<AUTHOR>J, J</AUTHOR>
<PUBLISHER>Books Ltd</PUBLISHER>
</BOOK>
novel.insertChildBefore(novel.AUTHOR[0], <PRICE>19.99</PRICE>);
trace(novel);
}
}
}
As an alternative to the insertChildAfter( ) approach (1)
package{
import flash.display.Sprite;
public class Main extends Sprite{
public function Main(){
var novel:XML = <BOOK ISBN="0000000000">
<TITLE>ActionScript</TITLE>
<AUTHOR>J, J</AUTHOR>
<PUBLISHER>Books Ltd</PUBLISHER>
</BOOK>
novel.AUTHOR[0] = novel.AUTHOR[0] + <AUTHOR>D, V</AUTHOR>;
trace(novel);
}
}
}
As an alternative to the insertChildAfter( ) approach (2)
package{
import flash.display.Sprite;
public class Main extends Sprite{
public function Main(){
var novel:XML = <BOOK ISBN="0000000000">
<TITLE>ActionScript</TITLE>
<AUTHOR>J, J</AUTHOR>
<PUBLISHER>Books Ltd</PUBLISHER>
</BOOK>
novel.AUTHOR[0] += <AUTHOR>D, V</AUTHOR>;
trace(novel);
}
}
}
Use appendChild method to add new child to the end of existing xml data
package{
import flash.display.Sprite;
public class Main extends Sprite{
public function Main(){
var novel:XML = <BOOK ISBN="0000000000">
<TITLE>ActionScript</TITLE>
<AUTHOR>J, J</AUTHOR>
<PUBLISHER>Books Ltd</PUBLISHER>
</BOOK>
novel.appendChild(<DESCRIPTION>A modern classic</DESCRIPTION>);
trace(novel);
}
}
}