XML : sql element name using getname()

I am new on PHP and xml.

This is the xml file I'm using.

  <product product_id = '4'>       <category_id>5</category_id>      <name> chocolate </name>      <price> 120 </price>      <unit> piece </unit>      <quantity> 100 </quantity>      <brandname> catberry </brandname>      <image>NULL</image>      <offer>NULL</offer>  </product>    

I cannot get the children element of product.

following loop doesn't work. How can it be done?

code:

function update_products($id, $xml) { include_once('config.php');

  foreach ($xml->children() as $key  ) {            echo $key->getname().'</br>';          foreach ($xml->children->children as $child ) {              echo $child->getname();               }  }    

}

No comments:

Post a Comment