0

我有一个要在 sql 中上传的 xml 文件

xml就像

 <catalog>
  <products>
  <product>
  <ID>0079</ID>
  <NAME>Casa</NAME>
  <feature name="material">cemento</feature>
  </product>
  </products>
  </catalog>

我愿意:

  $xml = simplexml_load_file('prova.xml');
  $listProducts = $xml->products;
  foreach ($listProducts->product as $product)
  { 
   $name           = $product->NAME;
   $id= $product->ID;
    ....................

但问题是我必须定义变量“FEATURE”

我想在我的 sql 中插入值“CEMENTO”

我能怎么做?

4

1 回答 1

0

看看它是否有效

$feature = $product->feature;
$featureName = $product->feature->attributes()->name;

更新

foreach ($listProducts->product as $product)
{ 
    $name = $product->NAME;
    $id= $product->ID;

    foreach ($product->feature as $feature)
    { 
        $featureName = $feature->attributes()->name;
    }

...

于 2013-03-29T22:14:54.320 回答