Adding new Attributes and Elements
var novel:XML = <BOOK ISBN="0141182806>
<TITLE>Ulysses</TITLE>
<AUTHOR>Joyce, James</AUTHOR>
<PUBLISHER>Hi Books</PUBLISHER>
<DESCRIPTION>A <B>very</B> thick book.</DESCRIPTION>
</BOOK>;
<TITLE>Ulysses</TITLE>
<AUTHOR>Joyce, James</AUTHOR>
<PUBLISHER>Hi Books</PUBLISHER>
<DESCRIPTION>A <B>very</B> thick book.</DESCRIPTION>
</BOOK>;
Modify existing element or attribute
novel.TITLE = "Last Ulysses"
novel.@ISBN = "015687982928";
novel.@ISBN = "015687982928";
Result:
<BOOK ISBN="015687982928>
<TITLE>Last Ulysses</TITLE>
<AUTHOR>Joyce, James</AUTHOR>
<PUBLISHER>Hi Books</PUBLISHER>
<DESCRIPTION>A <B>very</B> thick book.</DESCRIPTION>
</BOOK>
<TITLE>Last Ulysses</TITLE>
<AUTHOR>Joyce, James</AUTHOR>
<PUBLISHER>Hi Books</PUBLISHER>
<DESCRIPTION>A <B>very</B> thick book.</DESCRIPTION>
</BOOK>
Adding new elements
novel.SETTING.CITY = "Rome"
novel.SETTING.COUNTRY = "Italy";
novel.SETTING.COUNTRY = "Italy";
Result:
<BOOK ISBN="015687982928>
<TITLE>Last Ulysses</TITLE>
<AUTHOR>Joyce, James</AUTHOR>
<PUBLISHER>Hi Books</PUBLISHER>
<DESCRIPTION>A <B>very</B> thick book.</DESCRIPTION>
<SETTING>
<CITY>Rome</CITY>
<COUNTRY>Italy</COUNTRY>
</SETTING>
</BOOK>
<TITLE>Last Ulysses</TITLE>
<AUTHOR>Joyce, James</AUTHOR>
<PUBLISHER>Hi Books</PUBLISHER>
<DESCRIPTION>A <B>very</B> thick book.</DESCRIPTION>
<SETTING>
<CITY>Rome</CITY>
<COUNTRY>Italy</COUNTRY>
</SETTING>
</BOOK>
Adding new attributes
novel.SETTING.@CITY = "Rome"
novel.SETTING.@COUNTRY = "Italy";
novel.SETTING.@COUNTRY = "Italy";
Result:
<BOOK ISBN="015687982928>
<TITLE>Last Ulysses</TITLE>
<AUTHOR>Joyce, James</AUTHOR>
<PUBLISHER>Hi Books</PUBLISHER>
<DESCRIPTION>A <B>very</B> thick book.</DESCRIPTION>
<SETTING CITY="Rome" COUNTRY="Italy" />
</BOOK>
<TITLE>Last Ulysses</TITLE>
<AUTHOR>Joyce, James</AUTHOR>
<PUBLISHER>Hi Books</PUBLISHER>
<DESCRIPTION>A <B>very</B> thick book.</DESCRIPTION>
<SETTING CITY="Rome" COUNTRY="Italy" />
</BOOK>
Adding new child after a specific existing child
novel.insertChildAfter(novel.AUTHOR[0], <AUTHOR>Dave Luxtor</AUTHOR>);
Adding new child before a specific existing child
novel.insertChildBefore(novel.AUTHOR[0], <PRICE>30.00</PRICE>);
Adding new child before all existing child
novel.prependChild(<PAGECOUNT>340</PAGECOUNT>);
Deleting Elements and Attributes
delete novel.@ISBN;//Removes the ISBN attribute from the <BOOK> element.
delete novel.TITLE;
//Removes the <TITLE> element from the <BOOK> element.
delete novel.*;
//Removes the <TITLE>, <AUTHOR>, <PUBLISHER>, etc. elements from the <BOOK> element.
delete novel.TITLE.*;
//Removes the text content from the <TITLE> element.
delete novel.@*;
//Removes all attributes.
0 Responses to ActionScript 3.0 - Manage Xml Obj
Part 4
Something to say?