AnewtXMLDomElement class

Element DOM node.

Class Overview

Element DOM node.

This is a node type that corresponds to an XML element (tag). Note that the attribute API does not strictly match the W3C DOM standard. Instead of using a special attribute class, a simple associative-array based approach is used. This means there is no get_attribute_node method. instead, use methods such as get_attribute instead to retrieve the (string) value of an attribute.

Public Methods

__construct($tag_name, $attributes=null)

Create a new document element.

Parameters

$tag_name

The tag name for this element

$attributes

Associative array with initial attribute values for this element (optional). This parameter is for convenience only; you can always set attributes later.

See also

Attribute methods

has_attributes()

Return whether this element has attributes.

Return value

True if the element has attributes; false otherwise.

has_attribute($name)

Check whether this element has the given attribute.

Parameters

$name

The attribute name to test.

Return value

True if the element has the given attribute; false otherwise.

get_attribute($name)

Get value for the given attribute.

The attribute must be set for this method to succeed.

Parameters

$name

The name of attribute to retrieve the value for.

Return value

The value of the given attribute.

See also

set_attribute($name, $value)

Set value for the given attribute.

Parameters

$name

The name of attribute for which to set the value.

$value

The value of the attribute.

See also

get_attributes()

Get all attribute names and values.

Return value

Associative array with all attribute names and values.

See also

set_attributes($attributes)

Set multiple attributes at once.

This is a convenience method.

Parameters

$attributes

Associative array of attributes.

See also

remove_attribute($name)

Remove the given attribute from this element.

This function does nothing if the attribute was not set.

Parameters

$name

The name of attribute to remove.

Node methods

append_child_text($text)

Append a text node.

Parameters

$text

The text to append.

See also

append_child_raw($data)

Append a raw text node.

Parameters

$data

The raw text to append.

See also

Rendering methods

render($indent_level=0)

Render this element to a string.

Parameters

$indent_level

The indentation level to use for block level elements. Don't specify this attribute when calling this method, it's useful for internal purposes only.

Return value

Rendered string with XML data.

_build_attribute_string() [private]

Build an attribute string for this element.

Return value

String containing name=value pairs.

Public Attributes

$render_as_block

Whether this element should be rendered as a block (the default).

If false, the element is rendered inline, without indentation and surrounding newlines.

$always_render_closing_tag

Whether the closing tag for this element should always be rendered in full instead of using shorthand notation.

This is needed for e.g. the script tag in XHTML because of browser imcompatibilities.

Protected Attributes

Inheritance

Base Classes

Inherited members