2014-10-29 92 views
0
<?xml version="1.0" encoding="utf-8"?> 
<form> 
    <fields name="profile"> 
     <fieldset name="profile" label="PLG_USER_PROFILE_SLIDER_LABEL"> 
      <field name="address1" type="text" id="address1" description="PLG_USER_PROFILE_FIELD_ADDRESS1_DESC" filter="string" label="PLG_USER_PROFILE_FIELD_ADDRESS1_LABEL" size="30"/> 
     </fieldset> 
    <fields> 
</from> 

如何在现有节点字段中使用php插入节点。如何在现有XML文件中插入节点搜索特定的现有节点,然后使用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); 

它运行,但将插入节点形式节点内字段集节点内未插入。

+0

使用PHP的DOMDocument http://php.net/manual/en/domdocument.loadxml.php – Trone 2014-10-29 05:40:05

回答

0

在下面的代码是的,我会找到解决办法.....

$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);