【发布时间】:2021-08-08 08:02:20
【问题描述】:
我一直在从 xml 文件中读取属性。
xml 文件的示例如下:
<products products_num="358">
<product product_id="71166" type="main" product_counter="1">
<product_id>71122</product_id>
<sku>TN245</sku>
<model>37TN245Y</model>
<name>PRODUCT NAME</name>
<manufacturer>OEM</manufacturer>
<url>http://www.mysite.xx/index.php?route=product/product&product_id=71122</url>
<product_categories prod_cat_num="1">
<category_path category_id="48">CATEGORY -> CATEGORY</category_path>
</product_categories>
<mpn>-</mpn>
<barcode>-</barcode>
<date_added>2021-03-17 15:16:26</date_added>
<last_modified>2021-03-17 15:16:26</last_modified>
<description><![CDATA[DESCRTION]]></description>
<images>
<image_url type="main">http://www.mysyte.xx/image/catalog/product/10061.jpg</image_url>
</images>
<price tax_rate="24%" customer_perc="50.00%" currency="EUR">
<price_original>7.9300</price_original>
<price_with_perc>11.8950</price_with_perc>
<price_with_tax>14.7498</price_with_tax>
</price>
<instock>Y</instock>
<shipping>Y</shipping>
<minimum_quantity>1</minimum_quantity>
<availability status="In Stock" quantity="32" id="7"/>
</product>
</products>
我正在使用以下代码
$family = $this->getCurrentElement($object->product_categories->product_categories);
$this->_product['attribute'] = $family['category_id'];
我可以读取 xml 的所有其他元素,但不能读取 category_id。所以我试图捕获字符串 category_id 没有运气。
有什么帮助吗?
谢谢
【问题讨论】:
-
所以您要更新 xml?
-
试试
$family->category_path['category_id'](因为$family包含product_categories并且id在里面的category_path元素上) -
$this->getCurrentElement长什么样子?
标签: php xml xml-parsing