jedistev
03-11-2009, 11:47 AM
Hi
i have been working PHP for last two weeks i have overcome with it and enjoy every mins ..cos i'm JSP person for many years or AJAX guy :)
there is problem with Remove Child on XML in PHP
i am able to remove one line of Remove Child but cannot do more than one and keep nothing happened
here is example of XML
<?xml version="1.0" ?>
- <msgBody>
<email>test@test.org</email>
<email>test@test.com</email>
<msgExplanation>A non-fatal error occurred on power supply 1</msgExplanation>
<msgSystemAction>msgSystemAction</msgSystemAction>
<msgResponse>test</msgResponse>
<msgOperatorResponse>Dreaming</msgOperatorResponse>
</msgBody>
i wrote code
<?php
$emails = new DOMDocument;
$emails->Load("emails.xml");
$emailList=$emails->getElementsByTagName("msgBody")->item($id); // access the <emails> child
// look in the emails all the children with the tag <email>, choose the one with index 2.
$emailToRemove=$emailList->getElementsByTagName("msgOperatorResponse")->item($id);
$emailToRemove=$emailList->getElementsByTagName("msgExplanation")->item($id);
$emailToRemove=$emailList->getElementsByTagName("msgSystemAction")->item($id);
//we want to remove the children from <emails> so I used $emailList which points to <anytag> and removed the proper child.
$emailList->removeChild($emailToRemove);
$emails->save("emails1.xml");
<?xml version="1.0" ?>
- <msgBody>
<email>test@test.org</email>
<email>test@test.com</email>
<msgExplanation>A non-fatal error occurred on power supply 1</msgExplanation>
<msgResponse>test</msgResponse>
<msgOperatorResponse>Dreaming</msgOperatorResponse>
</msgBody>
and results is remove one line, is MsgSystemAction, nothing else
but i want remove more than one which i need remove msgOperatorResponse, msgExplanation, msgSystemAction
any idea where do i go wrong... your help would be savior !!!:thumbsup:
i have been working PHP for last two weeks i have overcome with it and enjoy every mins ..cos i'm JSP person for many years or AJAX guy :)
there is problem with Remove Child on XML in PHP
i am able to remove one line of Remove Child but cannot do more than one and keep nothing happened
here is example of XML
<?xml version="1.0" ?>
- <msgBody>
<email>test@test.org</email>
<email>test@test.com</email>
<msgExplanation>A non-fatal error occurred on power supply 1</msgExplanation>
<msgSystemAction>msgSystemAction</msgSystemAction>
<msgResponse>test</msgResponse>
<msgOperatorResponse>Dreaming</msgOperatorResponse>
</msgBody>
i wrote code
<?php
$emails = new DOMDocument;
$emails->Load("emails.xml");
$emailList=$emails->getElementsByTagName("msgBody")->item($id); // access the <emails> child
// look in the emails all the children with the tag <email>, choose the one with index 2.
$emailToRemove=$emailList->getElementsByTagName("msgOperatorResponse")->item($id);
$emailToRemove=$emailList->getElementsByTagName("msgExplanation")->item($id);
$emailToRemove=$emailList->getElementsByTagName("msgSystemAction")->item($id);
//we want to remove the children from <emails> so I used $emailList which points to <anytag> and removed the proper child.
$emailList->removeChild($emailToRemove);
$emails->save("emails1.xml");
<?xml version="1.0" ?>
- <msgBody>
<email>test@test.org</email>
<email>test@test.com</email>
<msgExplanation>A non-fatal error occurred on power supply 1</msgExplanation>
<msgResponse>test</msgResponse>
<msgOperatorResponse>Dreaming</msgOperatorResponse>
</msgBody>
and results is remove one line, is MsgSystemAction, nothing else
but i want remove more than one which i need remove msgOperatorResponse, msgExplanation, msgSystemAction
any idea where do i go wrong... your help would be savior !!!:thumbsup: