Creates the same XML hierarchy and dynamically specifies all element names, attribute names, attribute values, and element contents. : XML variable « XML « Flash / Flex / ActionScript






Creates the same XML hierarchy and dynamically specifies all element names, attribute names, attribute values, and element contents.

 

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var rootElementName:String = "BOOK";
        var rootAttributeName:String = "ISBN";
        var childElementNames:Array = ["TITLE", "AUTHOR", "PUBLISHER"];
        var bookISBN:String = "0000000000";
        var bookTitle:String = "ActionScript";
        var bookAuthor:String = "J, J";
        var bookPublisher:String = "Books Ltd";
        var novel:XML = <{rootElementName} {rootAttributeName}={bookISBN}>
            <{childElementNames[0]}>{bookTitle}</{childElementNames[0]}>
            <{childElementNames[1]}>{bookAuthor}</{childElementNames[1]}>
            <{childElementNames[2]}>{bookPublisher}</{childElementNames[2]}>
          </{rootElementName}>;
          
  
        trace(novel); 
    }
  }
}

        








Related examples in the same category

1.Invoke string method on XML data
2.Using + and += Operators to combine XML Nodes
3.Converting Strings to XML
4.Converting XML to Strings: The toString() method for XML objects will usually display the contents of an XML element including any tags.
5.Creates a variable refering to xml data child nodes
6.Change is made to the original document
7.' character can be used to delimit an attribute value in an XML literal, it is converted to the " character