我正在使用 simpleXml 生成 XML 文件...我有以下代码。
require_once('inc.php');
$query = $glb_connection->prepare('select * from table order by ID');
$query->execute();
$tree = $query->fetchAll();
$doc = $xml->init();
foreach($tree as $tr){
$xml_events = $doc->addChild('entr');
$xml_events->addAttribute('ID', $tr['ID']);
$xml_events->addAttribute('cmp', $tr['cmp']);
// add another child
$xml_supervisor = $xml_events->addChild('personDetail');
// instatiate class
$pro = new profile();
// passing getDetail method
$person = $pro->getDetail($tr['ID']);
// it prints all the detail of the ID as expected (using it to check if return true)
print_arr($person);
$xml_supervisor->addAttribute('firstname', $person->lastname);
$xml_supervisor->addAttribute('familyname', $person['lastname']);
}
$file = 'example.xml';
$xml->saveXML($doc,$file);
从上面的代码中,问题就在这里......我尝试从结果对象人那里调用字段名称,但我尝试过的两种方式都不起作用......
$xml_supervisor->addAttribute('firstname', $person->lastname);
$xml_supervisor->addAttribute('familyname', $person['lastname']);
如何从人员对象的生成结果中调用任何键或值???
有人有帮助...
这就是我调用时生成数组的方式
print_arr($person);
Array
(
[0] => Array
(
[ID] => 10
[lastname] => Sara
)
)