xml - Call to undefined method DOMElement::appendChid() in php -
following working
code generating xml -
working code link - 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 generated code -
<?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>
but trying add child node metadata
node , went wrong :(
xml generate -
<?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>
code not working -
codepad link - 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());
error -
fatal error: call undefined method domelement::appendchid()
let me know doing wrong ?
you have made spelling mistake, instead of appendchild
write appendchid
.
first correct it, , check happens.
Comments
Post a Comment