# TraversableXMLElement

Class providing XML functions with traversable interface Designed with immutability in mind A node can be either child or text, not both

author | Lukas Korinek
package | Default

### Methods

## __construct

    __construct(string $node, string $text, array $attributes, \NPS\Model\TraversableXMLElement $parent = null, array $children = array())

### Arguments

#### $node

`string`

Node name

#### $text

`string`

Content of the text node

#### $attributes

`array`

#### $parent

`\NPS\Model\TraversableXMLElement`

#### $children

`array`

## Makes an XML string output

    __toString() : string

### Response

`string`

## Adds a new child element

    addChild(\NPS\Model\TraversableXMLElement $element) : \NPS\Model\TraversableXMLElement

### Arguments

#### $element

`\NPS\Model\TraversableXMLElement`

### Response

`\NPS\Model\TraversableXMLElement`

## Creates an instance of a new tree root

    create(string $node, array $attributes = array(), string $text = '') : \NPS\Model\TraversableXMLElement

static

### Arguments

#### $node

`string`

Node name

#### $attributes

`array`

Attributes of the tag

#### $text

`string`

Text content of the node

### Response

`\NPS\Model\TraversableXMLElement`

## Creates a new instance out of a SimpleXMLElement

    fromSimpleXMLElement(\SimpleXMLElement $simple) : \NPS\Model\TraversableXMLElement

static

### Arguments

#### $simple

`\SimpleXMLElement`

### Response

`\NPS\Model\TraversableXMLElement`

## Creates a new instance out of a string

    fromString(string $str) : \NPS\Model\TraversableXMLElement

static

### Arguments

#### $str

`string`

### Response

`\NPS\Model\TraversableXMLElement`

## Gets an attribute

    getAttribute(string $key) : string

### Arguments

#### $key

`string`

Attribute name

### Response

`string`

or null on non existing attribute

## Gets attributes of this node

    getAttributes() : array

### Response

`array`

## Gets a child by a specific filter or the first one in the list

    getChild( $filter = null) : \NPS\Model\TraversableXMLElement

### Arguments

#### $filter

``

Can filter by node name

### Response

`\NPS\Model\TraversableXMLElement`

## Gets the children of this element

    getChildren( $filter = null) : array

### Arguments

#### $filter

``

Can filter by node name

### Response

`array`

## Gets the name of this node

    getNodeName() : string

### Response

`string`

## Gets the parent of this node

    getParent() : \NPS\Model\TraversableXMLElement

### Response

`\NPS\Model\TraversableXMLElement`

## Gets the siblings of this element

    getSiblings(string $filter = null) : array

### Arguments

#### $filter

`string`

### Response

`array`

## Gets the text of this node

    getText() : string

### Response

`string`

## Determines if this element is the root of a tree

    isRoot() : boolean

### Response

`boolean`

## Removes an attribute

    removeAttribute(string $name)

### Arguments

#### $name

`string`

Attribute name

## Removes a child element

    removeChild(\NPS\Model\TraversableXMLElement $element) : \NPS\Model\TraversableXMLElement

### Arguments

#### $element

`\NPS\Model\TraversableXMLElement`

### Response

`\NPS\Model\TraversableXMLElement`

## Sets an attribute

    setAttribute(string $name, string $value) : \NPS\Model\TraversableXMLElement

### Arguments

#### $name

`string`

Attribute name

#### $value

`string`

Attribute value

### Response

`\NPS\Model\TraversableXMLElement`

## Sets the text content of the element

    setText(string $text) : \NPS\Model\TraversableXMLElement

### Arguments

#### $text

`string`

### Response

`\NPS\Model\TraversableXMLElement`

## Returns simple XML element based on this traversable element

    toSimpleXMLElement() : \SimpleXMLElement

### Response

`\SimpleXMLElement`

### Properties

## Node name

    node : string

var | Node name

### Type(s)

`string`

## parent

    parent : \NPS\Model\TraversableXMLElement

var |

### Type(s)

`\NPS\Model\TraversableXMLElement`

## children

    children : array

var |

### Type(s)

`array`

## attributes

    attributes : array

var |

### Type(s)

`array`

## Text node of this element

    text : string

var | Text node of this element

### Type(s)

`string`