XmlUtil

Kind of class:class
Inherits from:none
Version:07/19/07
Author:Aaron Clinger, Mike Creighton, Chad Udell, Harry Williams
Classpath:org.casalib.util.XmlUtil
File last modified:Monday, 01 December 2008, 13:34:40

Summary


Class methods
  • getChildNodeByName (context:XMLNode, name:String) : XMLNode
    • Traverses through the child nodes and returns the first node it finds that matches specified name.
  • getChildNodesByName (context:XMLNode, name:String) : Array
    • Traverses through the child nodes and returns all nodes it finds that matches specified name.
  • getTextOfChildNodeByName (context:XMLNode, name:String) : String
    • Traverses through the child nodes and returns the text content of the first node it finds that matches specified name.
  • getTextOfChildNodesByName (context:XMLNode, name:String) : Array
    • Traverses through the child nodes and returns the text content of the first node it finds that matches specified name.
  • xmlToObject (xmlData:XML, convertNumbers:Boolean, convertBooleans:Boolean) : Object
    • Returns an easily navigable object from XML.
  • objectToXml (objectData:Object) : CoreXml
    • Returns XML converted from an Object.
  • extractText (node:XMLNode) : String
    • Traverses recursively through an XMLNode and its children returning the value of all text within.

Class methods

extractText

static function extractText (
node:XMLNode) : String

Traverses recursively through an XMLNode and its children returning the value of all text within.
Parameters:
node:
XMLNode to be traversed.
Returns:
  • String containing all text nodes' nodeValues concatenated together.

getChildNodeByName

static function getChildNodeByName (
context:XMLNode, name:String) : XMLNode

Traverses through the child nodes and returns the first node it finds that matches specified name.
Parameters:
context:
Node that contains the child nodes you are searching.
name :
Name of the target node.
Returns:
  • Returns the first node that matched specified name.

getChildNodesByName

static function getChildNodesByName (
context:XMLNode, name:String) : Array

Traverses through the child nodes and returns all nodes it finds that matches specified name.
Parameters:
context:
Node that contains the child nodes you are searching.
name :
Name of the target nodes.
Returns:
  • Returns an Array comprised of nodes that matched specified name.

getTextOfChildNodeByName

static function getTextOfChildNodeByName (
context:XMLNode, name:String) : String

Traverses through the child nodes and returns the text content of the first node it finds that matches specified name.
Parameters:
context:
Node that contains the child nodes you are searching.
name :
Name of the target node.
Returns:
  • Returns the text value of the node.

getTextOfChildNodesByName

static function getTextOfChildNodesByName (
context:XMLNode, name:String) : Array

Traverses through the child nodes and returns the text content of the first node it finds that matches specified name.
Parameters:
context:
Node that contains the child nodes you are searching.
name :
Name of the target nodes.
Returns:
  • Returns an Array comprised of the text values of the nodes that matched specified name.

objectToXml

static function objectToXml (
objectData:Object) : CoreXml

Returns XML converted from an Object.
Parameters:
objectData:
Basic Object to be coverted.
Returns:
Example:
  • var xmlObject:Object         = new Object();
    this.xmlObject.wrapper       = new Object();
    this.xmlObject.wrapper.group = "friends";
    this.xmlObject.wrapper.name  = new Array("Greg", "Jose", "Dave", "Toby");
    
    var xmlData:CoreXml = XmlUtil.objectToXml(this.xmlObject);
    
    trace(this.xmlData); // traces <wrapper group="friends"><name>Toby</name><name>Dave</name><name>Jose</name><name>Greg</name></wrapper>
Usage note:
  • objectToXml ignores function, Button, TextField and MovieClip.

xmlToObject

static function xmlToObject (
xmlData:XML, convertNumbers:Boolean, convertBooleans:Boolean) : Object

Returns an easily navigable object from XML.
Parameters:
xmlData :
Defined or loaded XML to be coverted.
convertNumbers :
[optional] Indicates to either convert number strings to numbers true, or leave all numbers as strings false; defaults to true.
convertBooleans:
[optional] Indicates to either convert "true"/"false" strings to proper booleans true, or leave all booleans as strings false; defaults to true.
Returns:
  • An Object comprised of Arrays.
Example:
  • var birthdayXml:XML = new XML("<birthday><people><person><name>Aaron Clinger</name><birthdate month=\"January\" day=\"11\" /></person><person><name>John Doe</name><birthdate month=\"April\" day=\"21\" /></person></people></birthday>");
    
    var xmlObject:Object = XmlUtil.xmlToObject(this.birthdayXml);
    
    trace("Name is " + this.xmlObject.birthday[0].people[0].person[1].name[0].nodeValue);
    trace("Day born is " + this.xmlObject.birthday[0].people[0].person[1].birthdate[0].day);