r access of the form {ns:var}. We don't use
// _children() here because we can break out of the loop
// immediately once we find something.
if (strpos($var, ':') !== false) {
list($ns, $elt) = explode(':', $var, 2);
foreach ($this->_element->childNodes as $child) {
if ($child->localName == $elt && $child->prefix == $ns) {
return true;
}
}
} else {
foreach ($this->_element->childNodes as $child) {
if ($child->localName == $var) {
return true;
}
}
}
}
/**
* Map method calls to get the string value of the requested
* element. If there are multiple elements that match, this will
* return an array of those objects.
*
* @param string $var The element to get the string value of.
*
* @return mixed The node's value, null, or an array of nodes.
*/
public function __call($var, $unused)
{
$nodes = $this->_children($var);
if (!$nodes) {
return null;
} elseif (count($nodes) > 1) {
return $nodes;
} else {
return $nodes[0]->nodeValue;
}
}
/**
* Only for
PHP 5.1 and later. Remove all children matching $var.
*/
public function __unset($var)
{
$nodes = $this->_children($var);
foreach ($nodes as $node) {
$parent = $node->parentNode;
$parent->removeChild($node);
}
}
/**
*/
public function __toString()
{
return $this->_element->nodeValue;
}
/**
*/
protected function _children($var)
{
$found = array();
// Look for access of the form {ns:var}.
if (strpos($var, ':') !== false) {
list($ns, $elt) = explode(':', $var, 2);
foreach ($this->_element->childNodes as $child) {
if ($child->localName == $elt && $child->prefix == $ns) {
$found[] = $child;
}
}
} else {
foreach ($this->_element->childNodes as $child) {
if ($child->localName == $var) {
$found[] = $child;
}
}
}
return $found;
}
/**
* Required by the ArrayAccess interface.
*
* @internal
*/
public function offsetExists($offset)
{
if (strpos($offset, ':') !== false) {
list($ns, $attr) = explode(':', $offset, 2);