[英]Fatal error: Call to undefined method DOMElement::createTextNode()
I get the message Call to undefined method DOMElement::createTextNode() . 我收到消息调用未定义的方法DOMElement :: createTextNode()。
My xml file has the tag entries, which have various entryresult tags inside with number and title 我的xml文件中包含标签条目,其中包含带有数字和标题的各种entryresult标签
My code: 我的代码:
$dom = new DOMDocument;
$dom->load('results.xml');
$student = $dom->documentElement;
$studentinfo = $student->getElementsByTagName('title')->item(0);
$newName = $student->createTextNode('Book1');
$student->replaceChild($newName, $student);
$dom->saveXML();
I want to get to entries->entryresult->title for a given number , edit the name of the title (for example bookA to bookB) and save it. 我想获得给定编号的entry-> entryresult-> title,编辑标题的名称(例如bookA到bookB)并保存。
The create*()
methods are part of the DOMDocument
, not the element nodes. create*()
方法是DOMDocument
一部分,而不是元素节点。
$newName = $dom->createTextNode('Book1');
If you don't have the document in the current context you can read it from DOMNode::$ownerDocument
. 如果当前上下文中没有该文档,则可以从DOMNode::$ownerDocument
读取该文档。
$newName = $student->ownerDocument->createTextNode('Book1');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.