Modify XML Root element with PHP SimpleXMLElement

How to change XML Root element with PHP SimpleXMLElement class

$extra_config = “602_0004f215cb72.cfg”;
$xml_resource = new SimpleXMLElement(‘config.xml’, 0, true);
$xml_resource[‘CONFIG_FILES’] = $extra_config  . “, phone1.cfg, sip.cfg”;
$xml_resource-> asXML(“config2.xml”);

config.xml

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<APPLICATION APP_FILE_PATH="sip.ld" CONFIG_FILES="phone1.cfg, sip.cfg" MISC_FILES="" LOG_FILE_DIRECTORY="" OVERRIDES_DIRECTORY="" CONTACTS_DIRECTORY="" LICENSE_DIRECTORY="">
 <APPLICATION_SPIP300 APP_FILE_PATH_SPIP300="sip_212.ld" CONFIG_FILES_SPIP300="phone1_212.cfg, sip_212.cfg"/>
 <APPLICATION_SPIP500 APP_FILE_PATH_SPIP500="sip_212.ld" CONFIG_FILES_SPIP500="phone1_212.cfg, sip_212.cfg"/>
 <APPLICATION_SPIP301 APP_FILE_PATH_SPIP301="sip_313.ld" CONFIG_FILES_SPIP301="phone1_313.cfg, sip_313.cfg"/>
 <APPLICATION_SPIP501 APP_FILE_PATH_SPIP501="sip_313.ld" CONFIG_FILES_SPIP501="phone1_313.cfg, sip_313.cfg"/>
 <APPLICATION_SPIP600 APP_FILE_PATH_SPIP600="sip_313.ld" CONFIG_FILES_SPIP600="phone1_313.cfg, sip_313.cfg"/>
 <APPLICATION_SPIP601 APP_FILE_PATH_SPIP601="sip_313.ld" CONFIG_FILES_SPIP601="phone1_313.cfg, sip_313.cfg"/>
 <APPLICATION_SSIP4000 APP_FILE_PATH_SSIP4000="sip_313.ld" CONFIG_FILES_SSIP4000="phone1_313.cfg, sip_313.cfg"/>
</APPLICATION>

config2.xml

<APPLICATION APP_FILE_PATH="sip.ld" CONFIG_FILES="602_0004f215cb72.cfg, phone1.cfg, sip.cfg" MISC_FILES="" LOG_FILE_DIRECTORY="" OVERRIDES_DIRECTORY="" CONTACTS_DIRECTORY="" LICENSE_DIRECTORY="">
 <APPLICATION_SPIP300 APP_FILE_PATH_SPIP300="sip_212.ld" CONFIG_FILES_SPIP300="phone1_212.cfg, sip_212.cfg"/>
 <APPLICATION_SPIP500 APP_FILE_PATH_SPIP500="sip_212.ld" CONFIG_FILES_SPIP500="phone1_212.cfg, sip_212.cfg"/>
 <APPLICATION_SPIP301 APP_FILE_PATH_SPIP301="sip_313.ld" CONFIG_FILES_SPIP301="phone1_313.cfg, sip_313.cfg"/>
 <APPLICATION_SPIP501 APP_FILE_PATH_SPIP501="sip_313.ld" CONFIG_FILES_SPIP501="phone1_313.cfg, sip_313.cfg"/>
 <APPLICATION_SPIP600 APP_FILE_PATH_SPIP600="sip_313.ld" CONFIG_FILES_SPIP600="phone1_313.cfg, sip_313.cfg"/>
 <APPLICATION_SPIP601 APP_FILE_PATH_SPIP601="sip_313.ld" CONFIG_FILES_SPIP601="phone1_313.cfg, sip_313.cfg"/>
 <APPLICATION_SSIP4000 APP_FILE_PATH_SSIP4000="sip_313.ld" CONFIG_FILES_SSIP4000="phone1_313.cfg, sip_313.cfg"/>
</APPLICATION>
Advertisements

Author: Shyju Kanaprath

In our daily life we learn lots of new things. As the time goes we forgets those and we may reach a situation where "Things You Probably Already Know, But Have Forgotten". I’m Shyju Kanaprath, the blogger of "Tech.. Logs.." and I blog here to avoid those kind of situations, at least for myself :) . This blog keep me in track on such times..

One thought on “Modify XML Root element with PHP SimpleXMLElement”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s