Installing and Using DOMIT! XML Parser

For those who use DOMIT, here is the how to install it and to use it in Yii:

Download DOMIT from: http://sourceforge.n…omit-xmlparser/

Create a folder name vendors in your protected folder.

Quote

protected/ vendors

Extract the downloaded .tar.gz, or .zip archived of DOMIT! into protected/vendors folder. So now it will be protected/vendors/domit

Loading DOMIT:

You can load it on the classes(either your controllers, models, or components) that use it by using:

<?php


Yii::import('your_path_to_domit');


Or, you can load it in the configuration file protected/config/main.php, then you won’t need to write Yii::import(‘your_path_to_domit’) everytime you want to import DOMIT! because it is now autoloaded:

<?php


return array (


   // autoloading model and component classes	


   'import'=>array(


      'application.vendors.*'


   )


);

To actually use DOMIT, you need to use the require_once() function in the classes that need it:

<?php


require_once('yourpath_to_domit/xml_domit_include.php'); // to use domit lite instead, use xml_domit_lite_include.php

You can start to instantiate the DOMIT_Document:



<?php


$domit = new DOMIT_Document();


$path = '[your path to your .xml file]';


$success = $domit->loadXml($path);





if ($success)


{


   $docElement = $domit->documentElement;


   echo $docElement->toNormalizedString(true);


}


else


{


   echo 'Failed to load XML';


}


Don't you love Yii ? I love it!

Why not use SimpleXML?

Quote

Why not use SimpleXML?

Well, of course why not use SimpleXML ? At anytime you can use SimpleXML.

This is not for a debate though. I just show some folks who have written code to write and read XML file with DOMIT using the old application library from the programmers before them.

Cheers!