hi every one i have an xml file and want to update my code is following
<gallerylist>
<record>
<movie>videos/15Avatar_HD.flv</movie>
<title>Avatar1</title>
<desc>It plays any kind of video file that Flash Player supports</desc>
<preview>videos/previews/6avatar.jpg</preview>
<imgplaylist>videos/imgplaylist/14p1.jpg</imgplaylist>
<category>Action</category>
</record>
</gallerylist>
and my php function is following:
function xml_update_video($id,$searchString)
{
$res=$this->selectVideo($id);
$searchString = $searchString;
$doc = new DOMDocument;
$doc->formatOutput = TRUE;
$doc->preserveWhiteSpace = FALSE;
$doc->load('../playlist.xml');
$xPath = new DOMXPath($doc);
$query = sprintf('//record[./title[text()="%s"]]', $searchString);
foreach($xPath->query($query) as $node)
{
$node->parentNode->removeChild($node);
}
$gallerylist = $doc->getElementsByTagName( "gallerylist" )->item(0);
$record = $gallerylist->appendChild($doc->createElement('record'));
$movie = $record->appendChild($doc->createElement('movie'));
$movie->appendChild($doc->createTextNode('videos/'.$res['videofile']));
$title = $record->appendChild($doc->createElement('title'));
$title->appendChild($doc->createTextNode($res['title']));
$desc = $record->appendChild($doc->createElement('desc'));
$desc->appendChild($doc->createTextNode($res['description']));
$preview = $record->appendChild($doc->createElement('preview'));
$preview->appendChild($doc->createTextNode('videos/previews/'.$res['previewImage']));
$imgplaylist = $record->appendChild($doc->createElement('imgplaylist'));
$imgplaylist->appendChild($doc->createTextNode('videos/imgplaylist/'.$res['playlistImage']));
$category = $record->appendChild($doc->createElement('category'));
$category->appendChild($doc->createTextNode($res['category']));
$doc->formatOutput = true;
$test1 = $doc->saveXML();
$doc->save('../playlist.xml');
}
$id is id of video file in database . with help of id i am adding new node in xml file after deleting node on basis of searchstring which is title.This code is not working properly. it add new node.
this file add new node .which is not right. this should be update existing node. but how ? can anyone help