This extension provides easy access to XML data from file or string.
Xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<AnyNodeName>
<Environment id="I">
<Node>1</Node>
<Node>2</Node>
<Node>3</Node>
<Node>4</Node>
</Environment>
<Environment id="II">
<Node>A</Node>
<Node>B</Node>
<Node>C</Node>
<Node>D</Node>
<Node>E</Node>
</Environment>
</AnyNodeName>
Sample usage:
public function test1()
{
$model = Environment::model($this->xml); // $this->xml can be path to file or xml string
$this->assertEquals(2, $model->length());
$this->assertEquals('I', $model->getAttribute("id"));
/// moveNext/movePrevious/move... affects model
$model->moveNext();
$this->assertEquals('II', $model->getAttribute("id"));
/// getNext/getPrevious/get.. don't
$this->assertEquals('I', $model->getFirst()->getAttribute("id"));
$this->assertEquals('II', $model->getAttribute("id"));
$model->moveFirst();
/// you can iterate over it
$count = 0;
$array = array();
foreach ($model as $k => $v)
{
$array[$v->getAttribute("id")] = $k;
$this->assertEquals('I', $model->getAttribute("id")); // and it will not affect '$model'
$count++;
}
$this->assertTrue(array_key_exists('I', $array));
$this->assertTrue(array_key_exists('II', $array));
$this->assertEquals(2, $count);
/// easy access to children
$this->assertEquals(4, $model->Node->length());
/// and to node value
$this->assertEquals('1', $model->Node->value());
$this->assertEquals('3', $model->Node->get(2)->value());
}
It is first public release, so it might be (and probably is) bugged.
I am waiting for feedback and suggestions.
You can download extension here.