
November 28th, 2006, 07:40 AM
|
|
Contributing User
|
|
Join Date: Apr 2007
Location: Hyderabad, AP, India
Posts: 49
Time spent in forums: 3 h 55 m 43 sec
Reputation Power: 3
|
|
|
Trouble with XML
Dear all,
I have an xml file named abc.xml. It has the following content.
php Code:
Original
- php Code |
|
|
|
<?xml version="1.0" encoding="ISO-8859-1"?> <contacts> <entry uri="sip:vinayg@company.org"> <name>Vinay</name> <sip> sip:vinayg@company.org </sip> <Number> 9885821530 </Number> </entry> <entry uri="sip:vivek@company.org"> <name>Vivek</name> <sip> sip:vivek@company.org </sip> <Number> 9885821530 </Number> </entry> <entry uri="sip:vinod@company.org"> <name>Vinod</name> <sip> sip:vinod@company.org </sip> <Number> 9885821530 </Number> </entry> </contacts>
To read data from this file, I use the following code.
php Code:
Original
- php Code |
|
|
|
function get($filename,$value) { $xml_data = simplexml_load_file($filename); } else { exit('Failed to open abc.xml.'); } $pt = "entry"; foreach($xml_data->$pt as $val) { if (strcmp($val[uri ], $value)== 0) { $disp="<name>"; $disp.=$val->name; $disp.="</name>"; $disp.="<sip>"; $disp.=$val->sip; $disp.="</sip>"; $disp.="<Number>"; $disp.=$val->Number; $disp.="</Number>"; } } return $disp; } $k=get("abc.xml","sip:vinod@company.org");
Now I must device functions to insert a new tag and delete an existing tag using the tag <entry>. Please note that the tag entry is an array.
Thanx for any help in advance.
With regards,
tvks
|