danbliz Posted January 20, 2010 Share Posted January 20, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.