Packagech.capi.data.xml
Classpublic class XMLDescriptor
InheritanceXMLDescriptor Inheritance Object

Represents an abstract XML descriptor. A XMLDescriptor is based on a XMLNode that is used to retrieve all the attributes and subnodes.

View the examples



Protected Properties
 PropertyDefined By
  node : XMLNode
[read-only] Defines the source XMLNode.
XMLDescriptor
Public Methods
 MethodDefined By
  
XMLDescriptor(source:Object)
Creates a new XMLDescriptor object.
XMLDescriptor
  
clone():Object
Returns a deep clone of the current XMLDescriptor.
XMLDescriptor
  
create(name:String):XMLDescriptor
[static] Creates a new XMLDescriptor object with the specified node name.
XMLDescriptor
  
getAttribute(name:String, defaultValue:String = null):String
Retrieves the specified attribute.
XMLDescriptor
  
getAttributeAsBoolean(name:String, defaultValue:Boolean = false):Boolean
Retrieves the specified attribute as Boolean.
XMLDescriptor
  
getAttributeAsInt(name:String, defaultValue:Number = 0, radix:int = 0):Number
Retrieves the specified attribute as integer.
XMLDescriptor
  
getAttributeAsNumber(name:String, defaultValue:Number = 0):Number
Retrieves the specified attribute as Number.
XMLDescriptor
  
Retrieves all the attributes name contained in the XMLDescriptor.
XMLDescriptor
  
getChild(name:String = null):XMLNode
Retrieves the first XMLNode that matches the specified name.
XMLDescriptor
  
getChildren(name:String = null):Array
Retrieves all the first level sub-nodes of the current XMLDescriptor.
XMLDescriptor
  
getName():String
Retrieves the XMLDescriptor node name.
XMLDescriptor
  
getText(strict:Boolean = false):String
Retrieves the text of the XMLDescriptor node.
XMLDescriptor
  
getTextAsBoolean(defaultValue:Boolean = false, strict:Boolean = false):Boolean
Retrieves the text node as Boolean.
XMLDescriptor
  
getTextAsInt(defaultValue:int = 0, radix:int = 0, strict:Boolean = false):int
Retrieves the node text as integer.
XMLDescriptor
  
getTextAsNumber(defaultValue:Number = 0, strict:Boolean = false):Number
Retrieves the text node as Number.
XMLDescriptor
  
getTextTrim(strict:Boolean = false):String
Retrieves the trimmed text of the XMLDescriptor node.
XMLDescriptor
  
hasAttribute(name:String):Boolean
Retrieves if the specified attribute exist in the XMLDescriptor on the root XMLNode.
XMLDescriptor
  
hasText(strict:Boolean = false):Boolean
Retrieves if the XMLDescriptor has a text.
XMLDescriptor
  
hasTextTrim(strict:Boolean = false):Boolean
Retrieves if the XMLDescriptor has a trimmed text.
XMLDescriptor
  
setAttribute(name:String, value:* = null):String
Set the value to the specified attribute.
XMLDescriptor
  
setName(name:String):void
Set the specified name to the XMLDescriptor.
XMLDescriptor
  
setText(text:String, strict:Boolean = false):void
Set the specified text to the node.
XMLDescriptor
  
toString():String
Retrieves the XMLDescriptor as a String.
XMLDescriptor
  
toXML():XML
Retrieves a XML of the XMLDescriptor.
XMLDescriptor
  
toXMLDocument():XMLDocument
Retrieves a XMLDocument of the XMLDescriptor.
XMLDescriptor
  
toXMLNode(deepClone:Boolean = true):XMLNode
Retrieves a cloned XMLNode.
XMLDescriptor
  
toXMLString():String
Retrieves the XMLDescriptor as a String.
XMLDescriptor
Protected Methods
 MethodDefined By
  
getTextNode(node:XMLNode = null):XMLNode
Retrieves the first text node in the first level sub-nodes of the specified node.
XMLDescriptor
  
isTextEnough(text:String = null):Boolean
Retrieves if the specified String is good enough to be considered as a valid node text.
XMLDescriptor
  
parseSource(source:Object):XMLNode
Parses the specified object to a XMLNode.
XMLDescriptor
Property Detail
nodeproperty
node:XMLNode  [read-only]

Defines the source XMLNode.


Implementation
    protected function get node():XMLNode
Constructor Detail
XMLDescriptor()Constructor
public function XMLDescriptor(source:Object)

Creates a new XMLDescriptor object.

Parameters
source:Object — The source object.

See also

Method Detail
clone()method
public function clone():Object

Returns a deep clone of the current XMLDescriptor.

Returns
Object — A deep clone of the current XMLDescriptor.
create()method 
public static function create(name:String):XMLDescriptor

Creates a new XMLDescriptor object with the specified node name.

Parameters

name:String — The node name.

Returns
XMLDescriptor — The created XMLDescriptor.
getAttribute()method 
public function getAttribute(name:String, defaultValue:String = null):String

Retrieves the specified attribute.

Parameters

name:String — The attribute name.
 
defaultValue:String (default = null) — The default value if the attribute doesn't exist.

Returns
String — The attribute value or the defaultValue if the attribute doesn't exist.
getAttributeAsBoolean()method 
public function getAttributeAsBoolean(name:String, defaultValue:Boolean = false):Boolean

Retrieves the specified attribute as Boolean. If the attribute doesn't exist, false is returned.

Parameters

name:String — The name of the attribute.
 
defaultValue:Boolean (default = false) — The default value.

Returns
Boolean — The boolean value or defaultValue if the attribute doesn't exist.

See also

getAttributeAsInt()method 
public function getAttributeAsInt(name:String, defaultValue:Number = 0, radix:int = 0):Number

Retrieves the specified attribute as integer. If the attribute isn't found, then the defaultValue is returned. Elste the specified radix is used to parse the value with the parseInt global function.

Note that the return type is denoted as Number because int and uint doesn't support the NaN value.

Parameters

name:String — The attribute name.
 
defaultValue:Number (default = 0) — The default value.
 
radix:int (default = 0) — The base for the attribute parsing.

Returns
Number — The value parsed as integer or the defaultValue (attribute not found) or NaN (not parsable value).

See also

getAttributeAsNumber()method 
public function getAttributeAsNumber(name:String, defaultValue:Number = 0):Number

Retrieves the specified attribute as Number. If the attribute isn't found, then the defaultValue is returned. Else the value is parsed using the parseFloat global function.

Parameters

name:String — The attribute name.
 
defaultValue:Number (default = 0) — The default value.

Returns
Number — The value parsed as a Number or the defaultValue (attribute not found) or NaN (not parsable value).

See also

getAttributes()method 
public function getAttributes():Array

Retrieves all the attributes name contained in the XMLDescriptor.

Returns
Array — An Array containing the name of the attributes.
getChild()method 
public function getChild(name:String = null):XMLNode

Retrieves the first XMLNode that matches the specified name. If the name is not specified, then the method will return the first child. Be aware that the XMLNode returned is a direct reference.

Parameters

name:String (default = null) — The node name.

Returns
XMLNode — The element of null if no node with the specified name has been found.
getChildren()method 
public function getChildren(name:String = null):Array

Retrieves all the first level sub-nodes of the current XMLDescriptor. Be aware that the XMLNode returned are direct references to the XMLNode.

Parameters

name:String (default = null) — The name of the nodes to retrieve.

Returns
Array — An Array with all the nodes that matches the specified name. If the name is null, then all the nodes are returned.
getName()method 
public function getName():String

Retrieves the XMLDescriptor node name.

Returns
String — The node name.
getText()method 
public function getText(strict:Boolean = false):String

Retrieves the text of the XMLDescriptor node. This method will retrieves the nodeValue attribute of the current XMLNode. If the strict argument is true, then this value will be returned however its value is null. If the strict argument is false and the nodeValue is null, the method will return the first text node nodeValue property.

Parameters

strict:Boolean (default = false) — Indicates if the text should be retrieved on the first text node if the nodeValue is null.

Returns
String — The text of the node or null.

See also

getTextAsBoolean()method 
public function getTextAsBoolean(defaultValue:Boolean = false, strict:Boolean = false):Boolean

Retrieves the text node as Boolean. If the node has no text, then the defaultValue is returned.

Parameters

defaultValue:Boolean (default = false) — The default value.
 
strict:Boolean (default = false) — Indicates if the text should be retrieved on the first text node if the nodeValue is null.

Returns
Boolean — The value parsed as a Boolean or the defaultValue (attribute not found).

See also

getTextAsInt()method 
public function getTextAsInt(defaultValue:int = 0, radix:int = 0, strict:Boolean = false):int

Retrieves the node text as integer. If the node has no text, then the defaultValue is returned.

Parameters

defaultValue:int (default = 0) — The default value.
 
radix:int (default = 0) — The base for the attribute parsing.
 
strict:Boolean (default = false) — Indicates if the text should be retrieved on the first text node if the nodeValue is null.

Returns
int — The value parsed as integer or the defaultValue (attribute not found) or NaN (not parsable value).

See also

getTextAsNumber()method 
public function getTextAsNumber(defaultValue:Number = 0, strict:Boolean = false):Number

Retrieves the text node as Number. If the node has no text, then the defaultValue is returned.

Parameters

defaultValue:Number (default = 0) — The default value.
 
strict:Boolean (default = false) — Indicates if the text should be retrieved on the first text node if the nodeValue is null.

Returns
Number — The value parsed as a Number or the defaultValue (attribute not found).

See also

getTextNode()method 
protected function getTextNode(node:XMLNode = null):XMLNode

Retrieves the first text node in the first level sub-nodes of the specified node. If the specified node is null the current node will be used.

Parameters

node:XMLNode (default = null) — The node to retrieve de text node.

Returns
XMLNode — The first text node or null if there is no text node.
getTextTrim()method 
public function getTextTrim(strict:Boolean = false):String

Retrieves the trimmed text of the XMLDescriptor node.

Parameters

strict:Boolean (default = false) — Indicates if the text should be retrieved on the first text node if the nodeValue is null.

Returns
String — The text of the node or null if there is only blank chars or no text.

See also

hasAttribute()method 
public function hasAttribute(name:String):Boolean

Retrieves if the specified attribute exist in the XMLDescriptor on the root XMLNode.

Parameters

name:String — The attribute name.

Returns
Booleantrue if the attribute exists.
hasText()method 
public function hasText(strict:Boolean = false):Boolean

Retrieves if the XMLDescriptor has a text.

Parameters

strict:Boolean (default = false) — Indicates if the text should be retrieved on the first text node if the nodeValue is null.

Returns
Booleantrue if the text node is not null and its length is greater than zero.

See also

hasTextTrim()method 
public function hasTextTrim(strict:Boolean = false):Boolean

Retrieves if the XMLDescriptor has a trimmed text.

Parameters

strict:Boolean (default = false) — Indicates if the text should be retrieved on the first text node if the nodeValue is null.

Returns
Booleantrue if the text node is not null and its length is greater than zero.

See also

isTextEnough()method 
protected function isTextEnough(text:String = null):Boolean

Retrieves if the specified String is good enough to be considered as a valid node text. This method simply checks if the specified text is not null and has a length greater than 0.

Parameters

text:String (default = null) — A node text.

Returns
Booleantrue if the String is good enough.
parseSource()method 
protected function parseSource(source:Object):XMLNode

Parses the specified object to a XMLNode. There are the actions of the method :

For the parsing with the XMLDocument object, the ignoreWhite attribute is always set to true.

Parameters

source:Object — The source object.

Returns
XMLNode

Throws
ArgumentError If — the source is null or invalid.
setAttribute()method 
public function setAttribute(name:String, value:* = null):String

Set the value to the specified attribute.

Parameters

name:String — The attribute name.
 
value:* (default = null) — The attribute value (null to delete).

Returns
String — The old value or null if the attribute didn't exist before.
setName()method 
public function setName(name:String):void

Set the specified name to the XMLDescriptor.

Parameters

name:String — The name.

setText()method 
public function setText(text:String, strict:Boolean = false):void

Set the specified text to the node.

Parameters

text:String — The text to set.
 
strict:Boolean (default = false) — Indicates if the text can be set in the first text node if the current node is not a text node.

See also

toString()method 
public function toString():String

Retrieves the XMLDescriptor as a String. This method will simply use the XMLNode.toString() method.

Returns
String — The XMLDescriptor as a String.
toXML()method 
public function toXML():XML

Retrieves a XML of the XMLDescriptor.

Returns
XML — A XML instance based on the XMLDescriptor.
toXMLDocument()method 
public function toXMLDocument():XMLDocument

Retrieves a XMLDocument of the XMLDescriptor.

Returns
XMLDocument — A XMLDocument instance based on the XMLDescriptor.
toXMLNode()method 
public function toXMLNode(deepClone:Boolean = true):XMLNode

Retrieves a cloned XMLNode.

Parameters

deepClone:Boolean (default = true) — If the XMLNode must be cloned deeply.

Returns
XMLNode — The cloned XMLNode.
toXMLString()method 
public function toXMLString():String

Retrieves the XMLDescriptor as a String. This method will simply use the XML.toXMLString() method.

Returns
String — The XMLDescriptor as a String.
Examples
     var xml:XML = <node name="myNode">textNode</node>
     var desc:XMLDescriptor = new XMLDescriptor(xml);
     trace(desc.getText()); //textNode
     trace(desc.getAttribute("name")); //myNode
     trace(desc.toXMLString());