Jump to content

PHP Dom


Feyy
 Share

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 :)

Edited by Feyy
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...