rhyspaterson Posted September 11, 2008 Share Posted September 11, 2008 Hey guys, I am reading in data from an XML file which looks like such: <?xml version="1.0" encoding="iso-8859-1"?> <building> <floor level="ground"> <printer> <name>PRINTER_1</name> <updated>2008-09-11T13:22:00+10:00</updated> </printer> <printer> <name>PRINTER_2</name> <updated>2008-09-11T13:22:01+10:00</updated> </printer> </floor> </building> - and the PHP code: <? $printers = $document->getElementsByTagName( "printer" ); foreach( $printers as $printer ) { $names = $printer->getElementsByTagName( "name" ); $name = $names->item(0)->nodeValue; $updateds = $printer->getElementsByTagName( "updated" ); $updated = $updateds->item(0)->nodeValue; echo "Printer name is $name and was updated at $updated"; } ?> Now everything is fine and dandy. However, i can't for the life of me figure out how to overwrite one of the elements. I know how to create and append, but not overwrite..! I would like to be able to search for a printer element, such as PRINTER_1 and overwrite the data in it's specific <updated></updated> tags (using the DOM if possible). Any suggestions? Cheers, Rhys Link to comment https://forums.phpfreaks.com/topic/123730-write-to-xml-file-using-the-dom/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.