# The SimpleXMLElement class

(PHP 5, PHP 7)

## Introduction

Represents an element in an XML document.

## Class synopsis

SimpleXMLElement implements Traversable {
/* Methods */
final public __construct ( string `$data` [, int `$options` = 0 [, bool `$data_is_url` = `FALSE` [, string `$ns` = "" [, bool `$is_prefix` = `FALSE` ]]]] )
public addAttribute ( string `$name` [, string `$value` [, string `$namespace` ]] ) : void
public addChild ( string `$name` [, string `$value` [, string `$namespace` ]] ) : SimpleXMLElement
public asXML ([ string `$filename` ] ) : mixed
public attributes ([ string `$ns` = `NULL` [, bool `$is_prefix` = `FALSE` ]] ) : SimpleXMLElement
public children ([ string `$ns` [, bool `$is_prefix` = `FALSE` ]] ) : SimpleXMLElement
public count ( ) : int
public getDocNamespaces ([ bool `$recursive` = `FALSE` [, bool `$from_root` = `TRUE` ]] ) : array
public getName ( ) : string
public getNamespaces ([ bool `$recursive` = `FALSE` ] ) : array
public registerXPathNamespace ( string `$prefix` , string `$ns` ) : bool
public __toString ( ) : string
public xpath ( string `$path` ) : array
}

## Table of Contents

- SimpleXMLElement::addAttribute — Adds an attribute to the SimpleXML element
- SimpleXMLElement::addChild — Adds a child element to the XML node
- SimpleXMLElement::asXML — Return a well-formed XML string based on SimpleXML element
- SimpleXMLElement::attributes — Identifies an element's attributes
- SimpleXMLElement::children — Finds children of given node
- SimpleXMLElement::__construct — Creates a new SimpleXMLElement object
- SimpleXMLElement::count — Counts the children of an element
- SimpleXMLElement::getDocNamespaces — Returns namespaces declared in document
- SimpleXMLElement::getName — Gets the name of the XML element
- SimpleXMLElement::getNamespaces — Returns namespaces used in document
- SimpleXMLElement::registerXPathNamespace — Creates a prefix/ns context for the next XPath query
- SimpleXMLElement::saveXML — Alias of SimpleXMLElement::asXML
- SimpleXMLElement::__toString — Returns the string content
- SimpleXMLElement::xpath — Runs XPath query on XML data