我试图从另外一个添加到一个的SimpleXMLElement,但我得到的错误:PHP拉,转换成XML,并追加到现有的XML文档
Warning: SimpleXMLElement::addChild(): Cannot add child. Parent is not a permanent member of the XML tree
$xml = $Global->serializeTradeShowTable();
$xmlDeser = simplexml_load_string($xml);
$doc = simplexml_load_file($path);
$tradeshows = $doc->Tradeshows;
foreach($xmlDeser->item as $item)
{
$name = (string)$item->friendlyName;
$formatted_name = str_replace(' ', '_', $name);
$sxe = new \SimpleXMLElement("<option></option>");
$sxe->addAttribute('name', $formatted_name);
$sxe->addAttribute('value', $name);
$sxe[0] = $name;
$tradeshows->addChild($sxe);
}
我米不知道为什么我不能将一种类型的SimpleXMLElement传递给另一个。是否需要某种类型的命名空间?任何帮助,将不胜感激。
请显示XML和期望结果的示例。 – Parfait