以下是working
生成此 XML 的代码 -
工作代码链接 - http://codepad.org/aX5HL6Vp
$dom = new DOMDocument('1.0');
$dom->xmlStandalone = false;
$manfiestNode = $dom->createElement('manifest',"");
$manfiestNodeAttr = $dom->createAttribute('identifier');
$date = new DateTime();
$manfiestNodeAttr->value = 'course_'.date_format($date,'U');
$manfiestNode->appendChild($manfiestNodeAttr);
$manfiestNode->appendChild($dom->createAttribute('xmlns:xsi'))->appendChild($dom->createTextNode("http://www.w3.org/2001/XMLSchema-instance"));
$metaData = $dom->createElement('metadata','');
$manfiestNode->appendChild($metaData);
$dom->appendChild($manfiestNode);
var_dump($dom->saveXML());
从代码生成的 XML -
<?xml version="1.0" standalone="no" ?>
<manifest identifier="com.scorm.golfsamples.contentpackaging.multioscosinglefile.20043rd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<metadata>
</metadata>
</manifest>
但我正在尝试将子节点添加到metadata
节点并且一切都出错了:(
要生成的 XML -
<?xml version="1.0" standalone="no" ?>
<manifest identifier="com.scorm.golfsamples.contentpackaging.multioscosinglefile.20043rd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<metadata>
<schema>ADL SCORM</schema>
<schemaversion>2004 3rd Edition</schemaversion>
</metadata>
</manifest>
代码不起作用-
键盘链接 - http://codepad.org/XLwp4AbQ
$dom = new DOMDocument('1.0');
$dom->xmlStandalone = false;
$manfiestNode = $dom->createElement('manifest',"");
$manfiestNodeAttr = $dom->createAttribute('identifier');
$date = new DateTime();
$manfiestNodeAttr->value = 'course_'.date_format($date,'U');
$manfiestNode->appendChild($manfiestNodeAttr);
$manfiestNode->appendChild($dom->createAttribute('xmlns:xsi'))->appendChild($dom->createTextNode("http://www.w3.org/2001/XMLSchema-instance"));
$metaData = $dom->createElement('metadata','');
$manfiestNode->appendChild($metaData);
$schema = $dom->createElement('schema','ADL SCORM');
$schemaVersion = $dom->createElement('schemaversion', '2004 3rd Edition');
$metaData->appendChid($schema);
$metaData->appendChid($schemaVersion);
$dom->appendChild($manfiestNode);
var_dump($dom->saveXML());
错误-
致命错误:调用未定义的方法 DOMElement::appendChid()
让我知道我做错了什么?