简体   繁体   中英

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>

How to insert node using php inside the fields existing node.

I will use bellow code for insert but not insert node properly.

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

It run but will insert node inside the form node not insert inside the fieldset node.

Yes, i will find solution at below code.....

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM