Jump to content

PHP Dom


Feyy

Recommended Posts

Hi,i am have a small problem with changing the text value of an element from a loaded xml file.Here is what i currently have using Dom:

<?php$doneUpdating = false;$updatedScore = 150;$document = new DOMDocument();$document->load( 'leaderboard.xml' ); $highscores = $document->getElementsByTagName( "highscore" ); $i=1; foreach( $highscores as $highscore ) { 	$actualscore = $highscore->getElementsByTagName( "score" ); 	$score = $actualscore->item(0)->nodeValue;	if($doneUpdating == false && $updatedScore > $score) {	//$score.nodeValue = $updatedScore;	   // i want to change the element text value here , above line is not working		$doneUpdating = true;	}	$names = $highscore->getElementsByTagName( "name" );	$name = $names->item(0)->nodeValue;	$i=$i+1;}?>

The XML file is formatted like this:

<leaderboard>	<highscore>		<score>30</score>		<name>TEST</name>	</highscore></leaderboard>

What i want to do is edit the value 30 in <score> and change it to my $updatedScore which is 150I don't want to use attributes , so i am looking for a way to set the element text value.Any help appreciated :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...