XPowerNodeList

Extends \XHT Implements \IteratorAggregate, \ArrayAccess

package

Default

Methods

Creates a document element from a raw XML data.

__(String $data) : \DOMDocumentFragment
inherited
uses

method must be inherited to work properly.

Arguments

$data

String



Raw XML data

Response

\DOMDocumentFragment



Returns a DOMDocumentFragment which content is the newly created element.

__construct

__construct( $xml_dir = NULL) 
inherited

Arguments

$xml_dir

__select

__select( $selectors) 
inherited

Arguments

$selectors

Appends an element to the list.

add(\DOMElement $node) : Boolean
see \XPowerNodeList::merge

Arguments

$node

\DOMElement



The element to append

Response

Boolean



Returns TRUE on success, or FALSE on error or failure.

Appends the new element passed in argument as a DOMElement or raw XML element to the selection.

append(Mixed $data) : \DOMNode
see \XPowerNodeList::appendTo

Arguments

$data

Mixed



The new element to append to the selection.

Response

\DOMNode

Returns the inserted element.

Appends the first element in the selection to the parent element passed in argument.

appendTo(\DOMElement $parent) : \DOMNode
see \XPowerNodeList::append

Arguments

$parent

\DOMElement



The new parent element of the selected element.

Response

\DOMNode

Returns the inserted element.

Gets or sets the selected element's attribute.

attr(String $name, String $value = null) 
see \XPowerNodeList::data

Arguments

$name

String



The attribute name to get for or to set for.

$value

String

[Optional]

If omitted the attribute value will be returned, otherwise the attribute value will be set to $value.

Gets the children of the selection.

children() : \XPowerNodeList
see \XPowerNodeList::find

Response

\XPowerNodeList

Closes and saves the changes to the current XML file.

close() : Boolean
inherited final

Response

Boolean



Returns TRUE on success, or FALSE on error or failure.

Connects to a XML document and loads it. The file extension is optional.

connect(String $file_name) : Boolean
inherited final

Arguments

$file_name

String



Response

Boolean



Returns TRUE on success, or FALSE on error or failure.

Gets the selected element attributes.

data(String $name = null) : Mixed
see \XPowerNodeList::attr

Arguments

$name

String

[Optional]

if set, the named attribute value will be returned.

Response

Mixed

Returns a DOMNamedNodeMap object if $name is not set, or a string otherwise.

Iterate through the elements in the list.

each(String $func_name) : \Returns
see \XPowerNodeList::map

Arguments

$func_name

String



a user defined function name or anonymous function name (function created with create_function function). The function will be called with two arguments; the first argument is an integer representing the element index, and the second argument is a DOMElement object of that element.

Response

\Returns

null on failure.

Seeks for some elements in the selection.

filter(String $selector = null) : \XPowerNodeList
see \XPowerNodeList::find

Arguments

$selector

String

[Optional]

CSS selector

Response

\XPowerNodeList

Seeks for an element in the selection.

find(String $selector = null) : \XPowerNodeList
see \XPowerNodeList::filter

Arguments

$selector

String

[Optional]

The selector of the element to seek for.

Response

\XPowerNodeList

Selects an element or a set of elements with a specific class attribute.

getElementByClass(String $class) : \XPowerNodeList
inherited final

Arguments

$class

String



Value of the class attribute

Response

\XPowerNodeList



Returns a XPowerNodeList object.

Selects an element with a specific unique id identifier.

getElementById(String $id) : \DOMNode
inherited final

Arguments

$id

String



Value of the id identifier

Response

\DOMNode



Returns a DOMNode object

Select an element or a set of elements with a specific attribute identifier.

getElementsByAttrName(String $attr) : \XPowerNodeList
inherited final

Arguments

$attr

String



Value of the attribue

Response

\XPowerNodeList



Returns a XPowerNodeList object

Selects an element or a set of elements with a specific tag.

getElementsByTagName(String $tag) : \XPowerNodeList
inherited final

Arguments

$tag

String



Tag name

Response

\XPowerNodeList



Returns a XPowerNodeList object

getIterator

getIterator() 

Giving an element in argument, gets the element index in the list.

getListElementIndex(\DOMElement $node) : Integer

Arguments

$node

\DOMElement

The element which index is expected for.

Response

Integer



Returns the element's index on success, or -1 on failure.

getNodeList

getNodeList() 

getSelectorNode

getSelectorNode( $selector) 
inherited

Arguments

$selector

Checks if the selection has a specific child.

hasChildren(Mixed $data) : Boolean

Arguments

$data

Mixed



The child element to seek for as a CSS selector or DOM element.

Response

Boolean

Returns TRUE on success, or FALSE on error or failure.

Does the oposite operation of XPowerNodeList::insertBefore.

insertAfter(\DOMElement $element) : \Returns
see \XPowerNodeList::insertBefore

Arguments

$element

\DOMElement



The reference element whom to insert after.

Response

\Returns

the newly inserted element.

Insert the first element in the selection before the element passed in argument.

insertBefore(\DOMElement $element) : \Returns
see \XPowerNodeList::insertAfter

Arguments

$element

\DOMElement



The reference element whom to insert before.

Response

\Returns

the newly inserted element.

Gets an item in the list by giving the index of the item as argument.

item(Integer $index) : \DOMElement

Arguments

$index

Integer



Item index in the list

Response

\DOMElement



Returns the element at $index on success, or throws an OutOfRangeException on error.

Iterate through the elements in the list and alter each element's value.

map(String $func_name) : \Returns
see \XPowerNodeList::each

Arguments

$func_name

String



A user defined function name, or an anonymous function name (function created with create_function function). $func_name will be passed two arguments; the current element index as the first argument, and the element node object (a DOMElement object) as the second argument. And the function must return a string which will be used as the current element node value.

Response

\Returns

null on failure.

Does the same thing as add at the only difference it can add multiple elements at once.

merge(\XPowerNodeList $list) 
see \XPowerNodeList::add

Arguments

offsetExists

offsetExists( $index) 

Arguments

$index

offsetGet

offsetGet( $index) 

Arguments

$index

offsetSet

offsetSet( $index,  $new_node) 

Arguments

$index

$new_node

offsetUnset

offsetUnset( $index) 

Arguments

$index

Trace back to the parent elements of the selection.

parents(String $selector = null) : \XPowerNodeList

Arguments

$selector

String

[Optional]

CSS selector

Response

\XPowerNodeList



Returns a XPowerNodeList object list of the element parents.

Removes the selection from the document.

remove() 

Removes an element from the list by passing the element index in the list in argument.

removeNodeFromList(Integer $index) : \Returns

Arguments

$index

Integer



Element index in the list

Response

\Returns

the removed element if the element could be removed, or FALSE on error or failure.

Replaces an elemet in the list with another element by passing the element's index (in the list) in argument.

replaceNodeFromIndex(\DOMNode $new_node, Integer $index) : Mixed

Arguments

$new_node

\DOMNode



The replacement element (DOMElement object)

$index

Integer



The replacing element index in the list

Response

Mixed



Returns an array containing the element as single on success or Boolean false on error.

Replaces the first element in the selection with a new element passed in argument as DOMElement or a raw XML data.

replaceWith(Mixed $data) : \Returns

Arguments

$data

Mixed



Replacement element reference as a raw XML data or a DOMElement.

Response

\Returns

the replacement element if success, or NULL on error or failure.

Selects an element or a set of elements using a CSS selector. Major CSS selector are supported; a little bit difference in pseudo-selector is the presence of a double dot (:) after the type selector (example: books > book:[price>=20.00$]).

select(String $selector = null, \DOMElement $context = null,  $flags = XHT_SELECT_RESET) : \XPowerNodeList
inherited final

Arguments

$selector

String

[Optional]

CSS selector for selection. Multiple selectors may be used at once by separating them with a comma (,). When omitted, all the document elements are selected as a whole.

$context

\DOMElement

[Optional]

A DOM element to refer to when selecting; it's the selection context (the element from which the selection begin).

$flags

Response

\XPowerNodeList



Returns a XPowerNodeList object

Gets the text content of the selection and its children.

text() : String

Response

String

Wrap the selection with an element passed in argument as a raw XML data or DOM element.

wrap(Mixed $data = null) 
tutorial

The method may return a null value on failure.

Arguments

$data

Mixed



A raw XML data or a DOM element to use to wrap the selection with.

Properties

Internal array to contain the list elements

list : Array
var

Type(s)

Array

Holds the number of elements in the list.

length : Integer
var

Type(s)

Integer

Holds XML document's directory name

xml_dir : String
inherited
var

Type(s)

String

Holds XML document element

parser : \DOMElement
inherited
var

Type(s)

\DOMElement

Holds the document root element

root : \DOMElement
inherited
var

Type(s)

\DOMElement

Current selected elements' list

xml_query : Array
inherited
var

Type(s)

Array

The current XML file name

file_name : String
inherited
var

Type(s)

String