Reputation: 55
I have a xml file like this:
<?xml version="1.0"?>
<zend-config xmlns:zf="http://framework.zend.com/xml/zend-config-xml/1.0/">
<tables>
<table>
<id>product</id>
<name>Sản phẩm</name>
<fields>
<field id="id" show="false">Id</field>
<field id="name" show="true">Tên sản phẩm</field>
<field id="price" show="true">Giá sản phẩm</field>
<field id="description" show="true">Miêu tả</field>
<field id="image" show="true">Hình ảnh</field>
<field id="last_update" show="false">Ngày cập nhật</field>
<field id="sold_qty" show="true">Số lượng đã bán</field>
<field id="current_qty" show="true">Số lượng hiện tại</field>
<field id="category_id" show="true">Thuộc danh mục</field>
</fields>
</table>
</tables>
</zend-config>
I use $reader = new Zend_Config_Xml('assets/config.xml', 'tables');
to read this file but field's content (as Tên sản phẩm or Giá sản phẩm) don't appear in new array:
Array (
[table] => Array (
[id] => product
[name] => Sản phẩm
[fields] => Array (
[field] => Array (
[0] => Array ( [id] => id [show] => false )
[1] => Array ( [id] => name [show] => true )
[2] => Array ( [id] => price [show] => true )
[3] => Array ( [id] => description [show] => true )
[4] => Array ( [id] => image [show] => true )
[5] => Array ( [id] => last_update [show] => false )
[6] => Array ( [id] => sold_qty [show] => true )
[7] => Array ( [id] => current_qty [show] => true )
[8] => Array ( [id] => category_id [show] => true ) ) ) ) )
What's wrong with xml file?
Upvotes: 1
Views: 68
Reputation: 7930
It doesn't really make sense to mix attributes and values in this manner, when using this Zend Config parser. I suggest you either move the value into a "value" attribute, or define all the keys in child elements.
<field id="name" show="true" value="Tên sản phẩm" />
Or:
<field>
<id>name</id>
<show>true</show>
<value>Tên sản phẩm</value>
</field>
Normal XML processing APIs - like SimpleXML or DOMDocument - could process your original XML, but this Zend Config parser doesn't seem to be set up to do that.
Upvotes: 2