Yii And Dynamic Xml

On the moment I’m working with a project what gets data from an XML file and store it into a database. It work fine with SimpleXML but it’s all kind of hardcoded. If the XML format change I have to change the code. I feel that is must be possible to make this more dynamic. Like a template how to interpretate the XML file. Is there something in Yii that can help me with this?

Simplefied example:

Feed 1



    <name>product one</name>



      <prop name="height"><value>100</value></prop>

      <prop name="width"><value>200</value></prop>

      <prop name="color"><value>green</value></prop>




    <name>product two</name>



      <prop name="height"><value>240</value></prop>

      <prop name="width"><value>500</value></prop>

      <prop name="color"><value>red</value></prop>




I can approach them like:

$products = simplexml_load_file("feed.xml");

foreach ($products as $key => $value) 


  echo $value->name;

  echo $value->properties->property[0]->attributes()->name;

  echo $value->properties->property[0]->value;


But i got another feed who uses other tag names.



    <name>product one</name>








How can I make this dynamic? I guess I’m not the first one to ran into this issue, but again I don’t know the right keywords to search for a solution. Do you know an Yii extention or another solution for this?


Well, It seems to be that the keyword is Xpath. A great option, just what I needed.