1

使用我的代码,我试图从 xml(以前是 svg)文件中获取路径数据,虽然我能够通过 $attributes 数组成功打印出数据,但使用 echo 它仍然会调用“对成员的调用在(第 136 行和第 156 行)中的非对象上的函数 attributes() 我根本看不出代码有什么问题,尽管在最坏的情况下,我总是可以使用 hack 将所选数据插入到数据库中while循环并在迭代时转发到所需的页面...我想知道我的代码到底有什么问题。它使用回显命令回显出正确的信息。它仍然在非对象错误上调用成员函数

while($number_of_array_path >=1)
{
//declares attributes based on path number for sodipodi attributes line136
$attributes = $xml_file_open->g->path[$path_incremental_counter]-
>attributes('sodipodi', true); 

//sets each attribute within an array and uses the path incremental counter for 
//that pourpose.
$type_array[$path_incremental_counter] = $attributes['type'];
$cx_array[$path_incremental_counter] = $attributes['cx'];
$cy_array[$path_incremental_counter] = $attributes['cy'];
$rx_array[$path_incremental_counter] = $attributes['rx'];
$ry_array[$path_incremental_counter] = $attributes['ry'];
echo $type_array[$path_incremental_counter];
echo "<br/>";                               
echo $cx_array[$path_incremental_counter];
echo "<br/>";                               
echo $cy_array[$path_incremental_counter];
echo "<br/>";
echo $rx_array[$path_incremental_counter];
echo "<br/>";
echo $ry_array[$path_incremental_counter];
echo "<br/>";                               


//same as above but for non"sodipodi" attributes. line 156
$attributes = $xml_file_open->g->path[$path_incremental_counter]->attributes();
// echo $attributes['id'];  
$style_array[$path_incremental_counter] = $attributes['style'];
$id_array[$path_incremental_counter] = $attributes['id'];
$d_array[$path_incremental_counter] = $attributes['d'];
echo $style_array[$path_incremental_counter];
echo "<br/>";
echo $id_array[$path_incremental_counter];
echo "<br/>";
echo $d_array[$path_incremental_counter];
echo "<br/>";



//increments path incremental counter
$path_incremental_counter = $path_incremental_counter + 1;
//decrements number of array path
$number_of_array_path = $number_of_array_path;                                                              
}
4

1 回答 1

0
foreach($xml_file_open->g->path[$shape_path_iteration_counter]->attributes() 
as $attribute => $value)

对于非 sodipodi 元素

foreach($xml_file_open->g->path[$shape_path_iteration_counter]->
attributes('sodipodi', true) as $attribute => $value)

对于 sodipodi 元素。

于 2012-05-20T05:33:03.707 回答