我有一个显示客户端徽标的 XML,并希望通过 PHP 面板添加徽标。当前的 XML 代码是:
<item>
<image><![CDATA[images/clients_5.gif]]></image>
</item>
<item>
<image><![CDATA[images/clients_6.gif]]></image>
</item>
<item>
<image><![CDATA[images/clients_7.gif]]></image>
</item>
<item>
<image><![CDATA[images/clients_8.gif]]></image>
</item>
<item>
<image><![CDATA[images/clients_9.gif]]></image>
</item>
<item>
<image><![CDATA[images/clients_10.gif]]></image>
</item>
<item>
<image><![CDATA[images/clients_11.gif]]></image>
</item>
<item>
<image><![CDATA[images/clients_12.gif]]></image>
</item>
<item>
<image><![CDATA[images/clients_13.gif]]></image>
</item>
<item>
<image><![CDATA[images/clients_14.gif]]></image>
</item>
<item>
<image><![CDATA[images/clients_15.gif]]></image>
</item>
<footer><![CDATA[copyright evolve entertainment and marketing solutions, 2009]]></footer>
</clients>
PHP代码是:
if(!empty($_FILES["logo"]["name"]))
{
$handle = new Upload($_FILES["logo"]);
$imgId = uniqid();
if ($handle->uploaded)
{
$handle->file_name_body_pre = $imgId;
$handle->image_resize = false;
$handle->Process(ROOT_PATH.'images/');
$handle->processed;
}
$imgName = $imgId.$_FILES["logo"]['name'];
$parent_path = "//main";
$next_path = "//main/clients/footer";
$xpath = new DomXPath($doc);
$parent = $xpath->query($parent_path);
$next = $xpath->query($next_path);
$imageNode = $doc->createElement('image');
$cdata=$doc->createCDATASection($imgName);
$imageNode = $imageNode->appendChild($cdata);
//$parent->item(0)->insertBefore($imageNode, $next->item(0));
$section = $doc->insertBefore($imageNode,$next->item(0));
$doc->save(XML_PATH.'clients.xml');
我想在页脚之前或子节点的顶部添加新节点。当我尝试上面的代码时,它会出现错误:未捕获的异常 'DOMException' 和消息'未找到错误'