Flash
  Home arrow Flash arrow Page 3 - Using XML and ActionScript with Flex Appli...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
FLASH

Using XML and ActionScript with Flex Applications
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 6
    2008-05-29

    Table of Contents:
  • Using XML and ActionScript with Flex Applications
  • Reading XML Data
  • Writing to and Editing XML Objects
  • Reflection
  • Getting the Class by Name

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using XML and ActionScript with Flex Applications - Writing to and Editing XML Objects


    (Page 3 of 5 )

    You can also write to and edit XML objects using ActionScript. There are three things you can do in this category:

    1. Modify existing data.
    2. Add new data.
    3. Remove existing data.

    Using XML

    You can modify existing data using the same E4X syntax you use to read the data on the left side of an assignment statement. For example, the following changes thetitleof the firstbook:

      xml.book[0].title = "Programming Flex 2: Edition 1";

    The following example changes the name of the secondauthorof thefirstbook:

      xml.book[0].authors.author[1].@first = "Joseph";

    If you want to add new data, you can use theappendChild(),prependChild(),insertChildBefore(), andinsertChildAfter()methods. Each method inserts a new XML node into anXMLorXMLListstructure. TheappendChild()andprependChild()methods each accept one parameter and insert the node at the end and at the beginning of the structure, respectively. The following adds a new publisher node to each book:

      xml.book[0].appendChild(<publisher>O'Reilly</publisher>);
      xml.book[1].appendChild(<publisher>O'Reilly</publisher>);

    You can use theinsertChildBefore()andinsertChildAfter()methods to add a new node before or after an existing node. The methods each require two parameters: the new node to add, and a reference to the existing node. The following adds a new publication date node (publicationDate) between the authors and publisher nodes of the books:

      xml.book[0].insertChildAfter(xml.book[0].authors, <publicationDate>2006</
      publicationDate>);
      xml.book[1].insertChildAfter(xml.book[1].authors, <publicationDate>2006</
      publicationDate>);

    You can remove elements using thedeleteoperator. The following example first adds a new middle attribute to an author node and then removes it:

      xml.book[0].authors.author[1] = <author first="Joey" middle="Persnippity" last="Lott"
      />;
      trace(xml.book[0].authors);
      delete xml.book[0].authors.author[1].@middle;
      trace(xml.book[0].authors);

    More Flash Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Programming Flex 2," published by...
     

    Buy this book now. This article is excerpted from chapter four of the book Programming Flex 2, written by Chafic Kazoun and Joey Lott (O'Reilly, 2007; ISBN: 059652689X). Check it out today at your favorite bookstore. Buy this book now.

    FLASH ARTICLES

    - Critical Flash Vulnerability Heats Up the Web
    - More on Nonpersistent Client-Side Remote Sha...
    - Nonpersistent Client-Side Remote Shared Obje...
    - Using the Decorator Pattern for a Real Web S...
    - Using Concrete Decorator Classes
    - Delving More Deeply into the Decorator Patte...
    - The Decorator Pattern in Action
    - A Simple Decorator Pattern Example
    - Decorator Pattern
    - Organizing Frames and Layers for Flash Anima...
    - Organizing Frames and Layers
    - Using XML and ActionScript with Flex Applica...
    - Interfaces and Events with ActionScript and ...
    - Manipulating Data with ActionScript in Flex ...
    - ActionScript Syntax for Flex Applications







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT