ok here my code

libxml_use_internal_errors(true);

$objXML = simplexml_load_file('MainRelease.xml','my_node'); // load xml file

if(!$objXML){
		$errors = libxml_get_errors();
		foreach($errors as $error)
		{
			echo $error->message,'<br />';
		}
}
else
{
	
$Result = $objXML->xpath('AllRelease/Release/name[@rdate="'.$DATERELEASE.'"]');


		if(empty($Result)){
			$AllRelease = $objXML->xpath("//AllRelease");
			$releas = $AllRelease[0]->prependChild2("Release");
			$dat = $releas->prependChild2("name");
			$dat->addAttribute("rdate",$DATERELEASE);
			$releas->prependChild("comment",$COMMENT);
			$Anime = $releas->prependChild2("Anime");
			$Anime->prependChild("popup",$POPUP);
			$Anime->prependChild("Title",$VIDEONAME);
			$Anime->prependChild("VideoUrl",$dir);
			$objXML->asXML("MainRelease.xml");
		}else{
			$Anime = $objXML->xpath("//Release");
			$anime = $Anime[0]->addChild("Anime");
			$anime->addChild("popup",$POPUP);
			$anime->addChild("Title",$VIDEONAME);
			$anime->addChild("VideoUrl",$dir);
			$objXML->asXML("MainRelease.xml");	
		}

}
?>

The probleme is with this line

$Result = $objXML->xpath('AllRelease/Release/name[@rdate="'.$DATERELEASE.'"]');

its always return empty on any condition.

im trying to make a condition statement so if this line return true do this or if false do the other statement.

So any help will be appreciate its my first time working on xml xpath and simpleXML.

Are you sure there's something in $DATERELEASE? And are you sure it's AllRelease, without an s?

Are you sure there's something in $DATERELEASE? And are you sure it's AllRelease, without an s?

this is the variable

$DATERELEASE = $_GET['daterelease'];

and here the form

<?php
		
		$dir = "./Video";
		$folder = scandir($dir); // scan folder (array)
		echo '<center><form id="typeFolder" name="typeFolder" action="checkFolder.php" method="get">';
		echo '<div class="refresh">Select the folder for insert video:<SELECT class="selectFolder" name="selectFolder">';
		foreach($folder as $folders){
			if($folders != '.' && $folders != '..'){
			echo '<option id="'.$folders.'" name="'.$folders.'" value="'.$folders.'">'.$folders.'</option>';
			}
		}
		echo '</SELECT></div>';
		echo 'Name Video File for Html(ex.A_Channel_Episode1): <input type="text" id="htmlname" name="htmlname" size="25" /><br />';
		echo 'Name Video Only(ex.A Channel Episode1): <input type="text" id="videoName" name="videoName" size="25" /><br />';
		echo 'Embed Video Link:<input type="text" id="linkEmbed" name="linkEmbed" size="50" /><br />';
		echo 'Name link1 video (ex. A Channel Episode1):<input type="text" id="namelink1" name="namelink1" size="25" /><br />';
		echo 'Name link2 video (ex. A Channel Episode1):<input type="text" id="namelink2" name="namelink2" size="25" /><br />';
		echo 'Popup:<input type="text" id="popup" name="popup" size="10" /><br />';	
		echo 'Date (ex. dd/mm/aaaa):<input type="text" id="daterelease" name="daterelease" size="25" /><br />';			
		echo 'Comment<textarea id="comment" name="comment" rows="10" cols="50"></textarea><br />';					
		echo 'Next link Video 1 or 2: 1<input type="radio" id="no1" class="unique" name="rad" value="1" checked="checked"/>2<input type="radio" id="no2" class="unique" name="rad" value="2" /><br />';
		echo '<div id="link"></div>';
		echo '<div id="deleteRefresh">Delete Html File<SELECT id="deleteLink" name="deleteLink">';
		foreach($folder as $folders){
			if($folders != '.' && $folders != '..'){
				foreach(scandir($dir.'/'.$folders) as $folderse){
					if($folderse != '.' && $folderse != '..'){
					echo '<option id="'.$folders.'/'.$folderse.'" name="'.$folders.'/'.$folderse.'" value="'.$folders.'/'.$folderse.'">'.$folders.'/'.$folderse.'</option>';
					}
				}
			}
		}
		echo '</SELECT></div><br />';
		echo '<input type="submit" id="submitType" name="submitType" value="CreateHTML" /><input type="submit" id="deleteType" name="deleteType" value="DeleteHTML" />';
		echo '</form></center><br />';
		?>

when i do echo i do get a value i don't know if my xpath syntax is wrong or i missing something im trying to cound if that daterelease exist if not do this. Yeah i check i wrote AllRelease like that no S. Because other xpath working but the one want that get the $DATERELEASE don't work always empty.

Could you post a piece of an xml file?

Could you post a piece of an xml file?

<AllRelease>
<Release>
	<name rdate="19/05/2011"/>
	<comment>WORKING WORKING WORKING</comment>
	<Anime>
		<popup>popup51</popup>
		<Title>Sket Dance Episode7</Title>
		<VideoUrl>Video/Sket_Dance/Sket_Dance_Episode7.html</VideoUrl>
	</Anime>
	<Anime>
		<popup>popup50</popup>
		<Title>Seikon No Qwaser 2 Episode5</Title>
		<VideoUrl>Video/Seikon_No_Qwaser_2/Seikon_No_Qwaser_2_Episode5.html</VideoUrl>
	</Anime>
	<Anime>
		<popup>popup49</popup>
		<Title>Ano Exorcist Episode5</Title>
		<VideoUrl>Video/Ao_No_Exorcist/Ao_No_Exorcist_Episode5.html</VideoUrl>
	</Anime>
</Release>
</AllRelease>

Well, actually, this works for me. Did you try setting $DATERELEASE manually? Maybe there's some problem with the my_node class?

Well, actually, this works for me. Did you try setting $DATERELEASE manually? Maybe there's some problem with the my_node class?

well the node_class only content 2 function the prepend function that take 2 element and the other prepend2 that take one element. The function work i just can't understand why the xpath always return empty im stuck in there. So if i give a specific date it always return empty and never get to do that else statement.

Does it enter that else if you remove the second argument, your class?

Does it enter that else if you remove the second argument, your class?

if i do this if(!empty($Result)) he does the else statement and i cant remove the second argument function will not work

if i do this if(!empty($Result)) he does the else statement and i cant remove the second argument function will not work

I found the solution took me time thank for the help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.