Re: PEAR::Config - reading XML files
| From: | Jeroen Houben | Date: | Thu, 03 Jul 2003 15:20:59 +0000 |
| Subject: | Re: PEAR::Config - reading XML files | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-6439@lists.php.net to get a copy of this message | ||
Bertrand Mansion wrote:
<jeroen@terena.nl> wrote :Hi Betrand, Bertrand Mansion wrote:Great ! Looks like the package is more powerful than I first thought :) Let's say this is the easy way then. I was actually thinking about something more complex, using container objects instead of the config object. I am happy to see that it works the easy way...Okay, but in the meantime I can use this I think. $config = new Config(); $conf =& $config->parseConfig('views.xml', 'xml'); $conf =& $config->parseConfig('models.xml', 'xml');but how do I parse more XML files in different sections? Can someone point me in the right direction please?Hi Jeroen, At the moment, there is no easy way to do that, particularly because PHP4 doesn't accept default values for arguments passed by reference :( But I think PHP5 will.But now how do I find entries inside say $conf? Say I would like to retrieve all the views, or find values inside views. here's my XML file: <views> <view name="insertable">I need to add some sort of "XPath" functionality to the Config_Container class. At the moment, the getItem() method is not recursive. $conf contains your root object. You can access, let's say view name="insertable" like this: $views =& $conf->getItem('section', 'views'); $viewInsertable =& $views->getItem('section', 'view', null, array('name'=>'insertable')); Okay thanks! That's a big help, I'll go and try :-)<model>contact</model> <classfile>views/Person_Insertable.class.php</classfile></view> <view name="editable"><model>contact</model> <classfile>views/Person_Editable.class.php</classfile></view> <view name="frozen"><model>contact</model> <classfile>views/Person_Frozen.class.php</classfile></view> </views>
In the future, I would like to have: $viewInsertable =& $conf->getItem('section', '/views/view', null, array('name'=>'insertable')); or something along these lines. One step instead of two. Yes that would be sweet.jeroen