-
Notifications
You must be signed in to change notification settings - Fork 0
class node
Denis Sibilev edited this page Jul 2, 2013
·
7 revisions
XML node management class:
<?php
class node implements ArrayAccess
{
# Creates an object from DOMNode
function __construct($node);
# Returns node name
function name();
# Returns node path
function path();
# Returns node value or null
function value();
# Returns node value or throws an exception
function checked_value();
# Returns node attributes map
function attributes();
# Returns attribute value or $default value if requested attribute doesn't exist
function attribute($name, $default = null);
# Returns parent node
function parent();
# Returns children node set
function children();
# Returns true if document has no children nodes and false otherwise
function blank();
# Inserts $new node before $node child node
function insert($new, $node);
# Replaces $old child node with $new node
function replace($new, $old);
# Removes $child node from child nodes
function remove($child);
# Returns internal DOMNode resource handle
function get();
}
?>
Usage example:
<?php
$xml = xml::load('/xml/library.xml');
$node = $xml->root();
foreach($node->attributes() as $name => $value)
{
var_dump($name);
var_dump($value);
}
foreach($node->children() as $child)
{
# ...
}
foreach($node->query('book') as $book)
{
var_dump($book['@author_id']);
var_dump($book['price/@currency']);
$book['price/@currency'] = 'usd';
}
?>