Chatbox

You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

1 PHP dom - changing specific nodes on 29/7/2012, 11:12 pm

Jack

avatar

Beta Tester
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:
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 Smile

View user profile

LGforum

avatar

Moderator
They have a nodeName property I believe, just like normal XML DOM.

Code:
if($i->nodeName && $i->nodeName === 'id' && $i->nodeValue == $id)
Each element, is a PHP DOMNode object, extended with DOMElement methods and properties too.

View user profile

Jack

avatar

Beta Tester
It worked, thank you Smile

View user profile

Sponsored content


View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum