请帮我理解替换子节点的问题
$dom = new DOMDocument();
$dom->load('cheat.xml');
$team1sabbr = $dom->getElementsByTagName('team1sabbr');
$textNode = $dom->createTextNode('value-1');
$textNode = $dom->importNode($textNode, true);
$team1sabbr->replaceChild($textNode, $oldNode);
$dom->save('cheat.xml');
Run Code Online (Sandbox Code Playgroud)
它抛出的错误就像
Fatal error: Call to undefined method DOMNodeList::replaceChild()
Run Code Online (Sandbox Code Playgroud)
cheat.xml 好像
<?xml version="1.0"?>
<matches>
<match id="2204">
<Game></Game>
<team1sabbr></team1sabbr>
<team2sabbr></team2sabbr>
Run Code Online (Sandbox Code Playgroud) 我试图使用循环打印,但它不打印下一个元素.
请给我一个简单的例子,它解释得最好.使用PHP DOM
其次,我可以获得一些具有该功能的Xth元素id.
更新
谢谢.在创建具有相同元素的元素时出现错误,id因此将其更改为class(抱歉是编程的新手,感谢振作起来).那么请你告诉我如何提取具有相同类名的所有元素,然后我可以从具有该类名的文档中获取一些Xth元素.