PHP dom - changing specific nodes
Page 1 of 1 • Share
- JackBeta Tester
- Forum Posts : 8
Member Since : 2011-11-02
Hi,
I've created a PHP script that loads information from an XML file into an array and it works perfectly, but I am having problems trying to create a script that changes the values of a specific node. The part that I'm having trouble with is trying to distinguish which node is the right node to change.
The XML file stores data about users and has 3 elements in one group: id, name and pass, so I use two foreach loops to get the XML data, one for the tags and one for the three child nodes that each tag has.
The code that I've got so far is:
Any help would be much appreciated
I've created a PHP script that loads information from an XML file into an array and it works perfectly, but I am having problems trying to create a script that changes the values of a specific node. The part that I'm having trouble with is trying to distinguish which node is the right node to change.
The XML file stores data about users and has 3 elements in one
The code that I've got so far is:
- Code:
public function saveUserData($id,$field,$newValue) {
$doc = new DOMDocument();
$doc->load('users.xml');
$x=0;
$users = $doc->getElementsByTagName('user');
foreach($users as $user) {
foreach($user->childNodes as $i) {
}
}
}
Any help would be much appreciated
- LGforumModerator
- Forum Posts : 77
Member Since : 2011-11-12
They have a nodeName property I believe, just like normal XML DOM.
- Code:
if($i->nodeName && $i->nodeName === 'id' && $i->nodeValue == $id)
- JackBeta Tester
- Forum Posts : 8
Member Since : 2011-11-02
It worked, thank you
- Sponsored content
Similar topics
Create an account or log in to leave a reply
You need to be a member in order to leave a reply.
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum