I may be mistaken but I don't think Zend_Config implements an Iterator interface so you probably can't do that. Also I don't think you can have multiple elements with the same name (at the same level). So "<items><item/><item/></items>" is not really a valid use of Zend_Config.
Tom
Thanks Tom for your quick help!
So this means I can access the needed node using below lines:
Suppose,
$config = new Zend_Config_Xml('/path/to/config.xml', '
mydata');
foreach($config->items …..) {
If(($config->items->type == 'clothes') { //can I check the 'type' attribute???
//do all processing
}
}
Thanks,
Vibhor
From: Tom Graham [mailto:tom.graham@jadu.co.uk]
Sent: Monday, August 17, 2009 5:00 PM
To: fw-mvc@lists.zend.com
Subject: [fw-mvc] Re: [fw-general] [fw-mvc] - Zend_Config_Xml with attributes
Hi,
Yes it is possible, the attributes are the same as if you had a child element of the same name. For example:
<mydata><items type="clothes">
<item belongs_to="cat1">
<name>ABCD</name>
</item>
</items>
</mydata>
Is the same as if you did:
<mydata><items>
<type>clothes</type>
<item>
<belongs_to>cat1</belongs_to>
<name>ABCD</name>
</item>
</items>
</mydata>
Hope that helps,
Tom2009/8/17 Vibhor Singh <vibhor@pivisions.net>
Hi all,
I want to use Zend_Config_Xml feature of ZF to automate my system. I am curious to know whether Zend_Config_Xml is able to read custom attributes of any xml file. If so, can someone please let me know how can this be achieved?
My xml file would look something like this:
<?xml version="1.0"?>
<mydata>
<items type="clothes">
<item belongs_to="cat1">
<name>ABCD</name>
</item>
<item belongs_to="cat3">
<name>EFGH</name>
</item>
</items>
<items type="shoes">
<item belongs_to="cat5">
<name>PQRS</name>
</item>
<item belongs_to="cat3">
<name>XYZ</name>
</item>
</items>
</mydata>
Now suppose I want to access data under this node(<items type="shoes">), then how should I do this using the Zend_Config_Xml object.
Can someone please help me in this? Any help would be greatly appreciated.
Regards,
Vibhor
没有评论:
发表评论