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 discovered Yii just last week ago, Its truly amazing.
I’ve got some XML fields in my model (using ACRecord) and I need to convert some of that XML nodes to standard variable that can be viewed and validated as any other active record in my model.
Basically I would like to keep using the Yii framework to add/save/validate my XML variables, is that possible in anyway? can you please provide me with some more examples?
I’m a bit confused how this is used you’re saying it can be used as a function and as a class? I need to access element data can you be a bit more clear in accessing it? How does it compare in usage to SimpleXML?
class QuestionnaireXML extends CXMLModel
{
public static function model($xml, $className=__CLASS__)
{
return parent::model($xml, $className);
}
}
I think this extension doesn’t do what I expected it to do. I was expecting to be able to use this class like an active record, defining rules in the derived class so that I could use the yii form builder to create a form from the model. However thinking about it a bit I would have expected the ‘model’ to be defined by an XML schema and the data to be saved in a a seperate XML file. Or perhaps the writing of an XML ‘database’ connection method, but then it all depends on what you are trying to do.
I need to access the node names and their parent nodes from an XSD file i.e., the xml schema. Is it possible to access those data using this extension?