cxmlmodel CXMLModel

  1. Documentation
  2. Change Log

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.
2 0
3 followers
1 114 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Others
Tags:
Developed by: lolo
Created on: Apr 29, 2010
Last updated: 7 years ago

Downloads

show all