Yii 1.1: cxmlmodel

CXMLModel
3 followers

This extension provides easy access to XML data from file or string.

Resources

Documentation

Requirements

  • Yii 1.0 or above

Installation

  • Extract the release file under protected/extensions

Usage

See 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());
}

Change Log

April 29, 2010

  • Initial release.

Be the first person to leave a comment

Please to leave your comment.

Create extension
Downloads
  • Yii Version: 1.1
  • License: New BSD License
  • Developed by: lolo
  • Category: Others
  • Votes: +2
  • Downloaded: 1,031 times
  • Created on: Apr 29, 2010
  • Last updated: never