Adding child node in xml file

superccd

New Member
I have an xml file\[code\]<?xml version="1.0" encoding="UTF-8"?><xml><settings><title>Calendar2</title><subTitle>Calendar2</subTitle></settings><events date="02-09-2010"><event><title>HTML Tags</title><description>HTML Tags</description></event></events></xml>\[/code\]How i can add another event inside events tag with respect to date\[code\]<?xml version="1.0" encoding="UTF-8"?> <xml> <settings> <title>Calendar2</title> <subTitle>Calendar2</subTitle> </settings> <events date="02-09-2010"> <event> <title>HTML Tags</title> <description>HTML Tags</description> </event> <event> <title>Another Title</title> <description>Another description</description> </event> </events> </xml>\[/code\]i used this code\[code\]$xml_str = file_get_contents($xmlfile);$xml = new SimpleXMLElement($xml_str);$event = $xml->events->addChild('event');$event->addChild('title', 'More Parser Stories');$event->addChild('description', 'This is all about the people who make it work.');file_put_contents($xmlfile, $xml->asXML());\[/code\]But it will add to the first node.How i can add to events tag with date 02-09-2010
 
Back
Top