edit an xml that uses key entries
Posted: Mon Dec 06, 2010 1:11 am
hope someone can point me in the right direction i am trying to use php to edit an xml file and have been able to do that just fine
however the file i now need to edit looks like this
XML File:
I am unable to figure out how to edit only joe's email address and leave the rest
the code i would normally use to edit an xml file would look like this:
thanks to anyone who can help!
-Jeff
however the file i now need to edit looks like this
XML File:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<dict>
<key>users</key>
<array>
<dict>
<key>Username</key>
<string>joe</string>
<key>Email</key>
<string>joe@hotmail.com</string>
<key>Password</key>
<string>this-is-joes-password</string>
</dict>
</array>
</dict>
the code i would normally use to edit an xml file would look like this:
Code: Select all
<?php
$xml = new DOMDocument('1.0', 'utf-8');
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
$xml->load('file.xml');
$element = $xml->getElementsByTagName('item')->item(0);
$name = $element->getElementsByTagName('name')->item(0);
$name->nodeValue = 'new name';
$element->replaceChild($name, $name);
thanks to anyone who can help!
-Jeff