AnewtXMLDomDocument class

Document DOM node.

Class Overview

Document DOM node.

The Document interface represents the entire HTML or XML document. Conceptually, it is the root of the document tree, and provides the primary access to the document's data.

See also

Constructor method

__construct()

Create a new DOM document instance.

Property methods

These methods can used to get or set several properties of the document.

get_document_type()

Get the document type.

Return value

The document type as string, or null if none is set.

See also

set_document_type($doctype)

Set the document type.

Parameters

$doctype

The document type as string, or null to unset.

See also

get_content_type()

Get the content type.

The default value is UTF-8.

Return value

The content type as string.

See also

set_content_type($content_type)

Set the content type.

Parameters

$content_type

The content type as string.

See also

get_encoding()

Get the document encoding.

Return value

Encoding as string, or null if none is set.

See also

set_encoding($encoding)

Set the document encoding.

Parameters

$encoding

The encoding as string, or null to unset.

See also

get_standalone()

Get whether this document is standalone.

This is a boolean value defaulting to null, which means no standalone attribute is added to the XML prolog.

Return value

Boolean or null if not set.

See also

set_standalone($standalone)

Set whether this document is standalone.

Parameters

$standalone

Boolean or null to unset.

See also

Node methods

These methods can be used to add new nodes to this document, or to create new nodes for this document. Note that you can also construct AnewtXMLDomNode subclasses directly.

append_child($root_element)

Append a child element to this document.

Documents can have only one child node (the document's root node), so this method can be called only once.

This method verrides the AnewtXMLDomNode::append_child() method to make sure there is only one top level element.

Parameters

$root_element

The root element to add.

& create_element($tagname, $attributes=null)

Create a new element for this document.

You should add the returned instance to the document yourself.

Parameters

$tagname

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.

Return value

New AnewtXMLDomElement instance.

& create_text_node($data)

Create a text node for the given data.

You should add the returned instance to the document yourself.

Parameters

$data

The textual data for this node.

Return value

New AnewtXMLDomText instance.

& create_raw_node($data)

Create a raw text node for the given data.

This is useful to add XML snippets generated by other means to a DOM tree.

You should add the returned instance to the document yourself.

Parameters

$data

The textual data for this node.

Return value

New AnewtXMLDomRaw instance.

& create_comment($data)

Create a comment node for the given data.

You should add the returned instance to the document yourself.

Parameters

$data

The comment text.

Return value

New AnewtXMLDomComment instance.

& create_document_fragment()

Create a document fragment node.

You should add the returned instance to the document yourself.

Return value

New AnewtXMLDomDocumentFragment instance.

Rendering methods

render()

Render this document to a string.

Return value

Rendered string with XML data.

flush()

Flush output to the browser.

This serializes the document into a string and sends it to the browser with the specified content type.

See also

flush_to_file($filename)

Flush output to a file.

This method renders the document and outputs it to the specified file.

Parameters

$filename

The filename to write the output to.

See also

Private Methods

xml_declaration() [private]

Return the XML declaration for this document.

Return value

XML declaration string.

Public Attributes

$node_name

The name of this node, depending on its type.

$document_element

Reference to the document element.

Protected Attributes

$render_xml_declaration [protected]

Whether to render the XML declaration.

This is detected automatically by default.

Private Attributes

$_xml_encoding [private]

The character encoding for this document.

$_xml_standalone [private]

Whether this document is specified to be standalone.

$_xml_version [private]

The XML version for this document.

This is always the literal value 1.0.

$_content_type [private]

The content type for this document.

Defaults to text/xml.

See also

$_doctype [private]

The document type declaration.

Null by default.

$__object_id_counter [private]

Object id counter.

Only for internal use.

Inheritance

Base Classes

Inherited members