使用PHP删除XML中节点内部的节点
我想从XML文件中删除一个特定节点,但代码中似乎遗漏了什么! 你能帮我弄清楚吗,例如,我想删除标签及其所有内部标签 XML结构:使用PHP删除XML中节点内部的节点,php,xml,removechild,Php,Xml,Removechild,我想从XML文件中删除一个特定节点,但代码中似乎遗漏了什么! 你能帮我弄清楚吗,例如,我想删除标签及其所有内部标签 XML结构: <students> <student> <username>sally</username> <subjects> <subjects>sub1</subjects> <subjects>sub2</subject
<students>
<student>
<username>sally</username>
<subjects>
<subjects>sub1</subjects>
<subjects>sub2</subjects>
<subjects>sub3</subjects>
</subjects>
</student>
<student>
<username>jojo</username>
<subjects>
<subjects>sub1</subjects>
<subjects>sub2</subjects>
<subjects>sub3</subjects>
<subjects>sub4</subjects>
<subjects>sub5</subjects>
</subjects>
</student>
</students>
电话:
delete_subjects('jojo', $fileName);
而不是
$xml->documentElement->removeNode($p)代码>尝试使用$user->removeChild($p)代码>
编辑:甚至$p->parentNode->removeChild($p)代码>很高兴听到,请将答案标记为已接受,以便其他用户知道问题已解决。
delete_subjects('jojo', $fileName);