Dealing with XML errors
SimpleXMLElement::addAttribute
SimpleXML
PHP Manual

# The SimpleXMLElement class

## Introduction

Represents an element in XML document.

## Class synopsis

SimpleXMLElement
SimpleXMLElement {
/* Methods */
void addAttribute ( string `$name` , string `$value` [, string `$namespace` ] )
SimpleXMLElement addChild ( string `$name` [, string `$value` [, string `$namespace` ]] )
mixed asXML ([ string `$filename` ] )
SimpleXMLElement attributes ([ string `$ns` [, bool `$is_prefix` ]] )
SimpleXMLElement children ([ string `$ns` [, bool `$is_prefix` = false ]] )
integer count ( void )
array getDocNamespaces ([ bool `$recursive` ] )
string getName ( void )
array getNamespaces ([ bool `$recursive` ] )
bool registerXPathNamespace ( string `$prefix` , string `$ns` )
array xpath ( string `$path` )
}

## 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::xpath — Runs XPath query on XML data

Dealing with XML errors
SimpleXMLElement::addAttribute
SimpleXML
PHP Manual