Jump to content

XML editing problem


danbliz

Recommended Posts

I have a xml file with a value in it that I want to increment by one each time the page is viewed. Here is the xml file:

 

<?xml version="1.0" encoding="utf-8"?>
<thermometer>
<goal goalNum="2553"><![CDATA[<b>2,553</b>]]></goal>
<current currentNum="102" />
</thermometer>

 

I need to increment currentNum by one. I keep trying different things, but can't seem to get it to work. Here is what I have:

 

$dom = new DOMDocument();
$dom->load('tharmameter.xml');
$xpath = new DOMXPath($dom);

$currentNumber = $xpath->query('thermometer/current/currentNum');
$newNum = $currentNumber + 1;
$currentNum->nodeValue = $newNum;
    
$dom->save('tharmameter.xml');

 

Can anyone tell me what I am doing wrong? Thanks!

Link to comment
https://forums.phpfreaks.com/topic/189170-xml-editing-problem/
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.