PHP SimpleXML select attributes

serena

New Member
I have an XML feed that looks like this:\[code\]<?xml version="1.0" encoding="UTF-8"?><productFeed version="1.0" timestamp="20100910:04:06:55"><product id="196"> <name>Lorem</name> <price>190.00</price> <description>Lorem Ipsum</description> <productURL> http://www.example.com</productURL> <imageURL> http://www.example.com/lorem.jpg </imageURL> <additional> <field name="country" value="http://stackoverflow.com/questions/3719266/IT" /> <field name="region" value="http://stackoverflow.com/questions/3719266/Rome" /> <field name="city" value="http://stackoverflow.com/questions/3719266/Rome" /> </additional> <categories> <category name="foobar" /> </categories></product> </productFeed>\[/code\]I'm trying to print out the category attribute, among other things with this script:\[code\]<?php$url = 'lorem.xml';$xml = simplexml_load_file($url);$expr = "/productFeed//product/additional/field[@value='http://stackoverflow.com/questions/3719266/Rome']/parent::*/parent::*";$result = $xml->xpath($expr);foreach($result as $item) { echo $item->name; echo $item->imageURL; echo $item->description; echo $item->price; echo $item->category->attributes()->name;}?>\[/code\]This produces an Warning: main() [function.main]: Node no longer exists error although the FireXPath Firebug plugin tells me I'm correctly selecting the attributes too.What am I doing wrong?Thanks
 
Back
Top