如何在搜索特定的现有节点内的现有xml文件中插入节点,然后使用php插入子自定义节点

如何在搜索特定的现有节点内的现有xml文件中插入节点,然后使用php插入子自定义节点,php,xml,Php,Xml,它运行,但将在表单节点中插入节点,而不是在字段集节点中插入节点 是的,我将在下面的代码中找到解决方案 $xmlfile = "profiles/profile.xml"; $dom = new DOMDocument(); $dom->load($xmlfile); $findnode= $dom->getElementsByTagName("/fieldset")->item

它运行,但将在表单节点中插入节点,而不是在字段集节点中插入节点


是的,我将在下面的代码中找到解决方案

 $xmlfile = "profiles/profile.xml"; 
                $dom = new DOMDocument();
                $dom->load($xmlfile);

                $findnode= $dom->getElementsByTagName("/fieldset")->item(0);
                $dom->documentElement->insertBefore($dom->createElement('section',"asdsad"),$findnode);
$dom->save($xmlfile);
使用php文档
 $xmlfile = "profiles/profile.xml"; 
                $dom = new DOMDocument();
                $dom->load($xmlfile);

                $findnode= $dom->getElementsByTagName("/fieldset")->item(0);
                $dom->documentElement->insertBefore($dom->createElement('section',"asdsad"),$findnode);
$dom->save($xmlfile);
 $dom = new DOMDocument();
        $dom->load($xmlfile);   
        $ids = $dom->getElementsByTagName('fieldset')->item(0);

        $child = $dom->createElement('tagname');
        $child->appendChild($dom->createTextNode('some text'));
        $ids->appendChild($child);