public class XMLElement

class.xmlelement.php #14

XMLElement is a class used to simulate PHP's DOMElement class. Each object is a representation of a HTML element and can store it's children in an array. When an XMLElement is generated, it is output as an XML string.

Constants

static string CRLF = PHP_EOL

The end-of-line constant.

Deprecated

This will be removed in the next version of Symphony

Methods

XMLElement __construct(string $name, string|XMLElement $value, array $attributes, boolean $createHandle)

The constructor for the XMLElement

Parameters
  • $name stringThe name of the XMLElement, 'p'.

  • $value string|XMLElement(optional) The value of this XMLElement, it can be a string or another XMLElement object.

  • $attributes array(optional) Any additional attributes can be included in an associative array with the key being the name and the value being the value of the attribute. Attributes set from this array will override existing attributes set by previous params.

  • $createHandle booleanWhether this function should convert the $name to a handle. Defaults to false.

void addProcessingInstruction(string $pi)

Adds processing instructions to this XMLElement

void appendChild(XMLElement $child)

Adds an XMLElement to the children array

void appendChildArray(array $children)

A convenience method to add children to an XMLElement quickly.

string generate(boolean $indent, integer $tab_depth, boolean $hasParent)

This function will turn the XMLElement into a string representing the element as it would appear in the markup. It is valid XML.

Parameters
  • $indent booleanDefaults to false

  • $tab_depth integerDefaults to 0, indicates the number of tabs (\t) that this element should be indented by in the output string

  • $hasParent booleanDefaults to false, set to true when the children are being generated. Only the parent will output an XML declaration if $this->_includeHeader is set to true.

string getAttribute(string $name)

Retrieves the value of an attribute by name

array getAttributes()

Accessor for $_attributes

array getChildren()

Accessor for $_children

string getName()

Accessor for $_name

integer getNumberOfChildren()

Returns the number of children this XMLElement has.

string|XMLElement getValue()

Accessor for $_value

void prependChild(XMLElement $child)

Adds an XMLElement to the start of the children array, this will mean it is output before any other children when the XMLElement is generated

void setAllowEmptyAttributes(string $value)

Specifies whether attributes need to have a value or if they can be shorthand on this XMLElement.

Parameters
  • $value string(optional) Defaults to true

void setAttribute(string $name, string $value)

Sets an attribute

Parameters
  • $name stringThe name of the attribute

  • $value stringThe value of the attribute

void setAttributeArray(array $attributes)

A convenience method to quickly add multiple attributes to an XMLElement

Parameters
  • $attributes arrayAssociative array with the key being the name and the value being the value of the attribute.

void setDTD(string $dtd)

Sets the DTD for this XMLElement

void setElementStyle(string $style)

Sets the style of the XMLElement. Used when the XMLElement is being generated to determine whether needs to be closed, is self closing or is standalone.

Parameters
  • $style string(optional) Defaults to 'xml', any other value will trigger the XMLElement to be closed by itself or left standalone if it is in the XMLElement::no_end_tags.

void setEncoding(string $value)

Sets the encoding for this XMLElement for when it's generated.

void setIncludeHeader(string $value)

Sets whether this XMLElement needs to output an XML declaration or not. This normally is only set to true for the parent XMLElement, eg. 'html'.

Parameters
  • $value string(optional) Defaults to false

void setSelfClosingTag(string $value)

Sets whether this XMLElement is self closing or not.

Parameters
  • $value string(optional) Defaults to true

void setValue(string|XMLElement $value, boolean $prepend)

Sets the value of the XMLElement. Checks to see whether the value should be prepended or appended to the children.

Parameters
  • $prepend boolean(optional) Defaults to true.

void setVersion(string $value)

Sets the version for the XML declaration of this XMLElement

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details