Hi With a simple xml file as follows, what would be the best and simplest way in php to edit 2 of the node values?... <pages> <page id="index"> <filename>index</filename> <pagename>Welcome</pagename> <pagearea>home</pagearea> <template>homepage</template> <keywords /> <description /> <order>2</order> </page> <page id="contact"> <filename>contact</filename> <pagename>Contact</pagename> <pagearea>general</pagearea> <template>default</template> <keywords /> <description /> <order>2</order> </page> </pages> Basically this xml stores page information for a simple cms im developing. I've been playing around for ages trying to find the best way to update page keywords and description nodes but havent found an easy way to do this. All i want to do is just go to the right page node and edit the keywords and descriptions and then save the xml file. It shouldnt be difficult but its causing me lots of grief. Any help would be greatly recieved. Cheers, Will
look at the dom xml functions on php.net, it can convert xml objects into php arrays, and back into xml again for you.
I've had a quick look but it seems an awful lot of code to do something relatively simple. Does anyone know a good example i could use to start myself off?
DOM is your best bet. The simplest way to edit any node is to use XPath. Just check my article about . When you get node you need with xpath then just change it value (eg $node->nodeValue = "something"; ) All objects are passed by refernece so changes will be made in main document as well. Then just use DomDocument::save() method and that's. It's just few lines of code if you know about xpath