Thread: savexml/loadxml
View Single Post
  #5  
Old 01-21-2010, 08:08 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Generating xml:

PHP Code:
temp.xml "";
with (temp.xml.addArrayMember("friends")) {
  for (
temp.plallplayers) {
    
with (addArrayMember("friend")) {
      
addArrayMember("account").addArrayMember("text") = temp.pl.account;
      
addArrayMember("nick").addArrayMember("text") = temp.pl.nick;
    }
  }
}
player.sendToClient("friends"temp.xml.savexmltostring()); 
Reading XML:
PHP Code:
temp.xml.loadxmlfromstring(data);
if (
temp.xml.size() >= && temp.xml[0].name=="friends") {
  for (
temp.i=0temp.i<temp.xml[0].size(); temp.i++) {
    if (
temp.xml[0][temp.i].name=="friend") {
      echo(
"account: " temp.xml[0][temp.i].getArrayMember("account").text);
      echo(
"nick: " temp.xml[0][temp.i].getArrayMember("nick").text);
    }
  }

You can also use node attributes, there are some small things to keep care of though, "name" will be renamed to "xmlname", and "text" will automatically hold the first "text" attribute.
Reply With Quote