[英]how to insert node in existing xml file inside search specific existing node then insert child custom node using php
<?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插入節點。
我將使用下面的代碼進行插入,但不能正確插入節點。
$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);
它會運行,但會在表單節點內插入節點,而不會在fieldset節點內插入。
是的,我將在以下代碼中找到解決方案.....
$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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.