This extension provides easy access to XML data from file or string.
protected/extensionsSee the following code example:
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()); }
Be the first person to leave a comment
Please login to leave your comment.