Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   savexml/loadxml (https://forums.graalonline.com/forums/showthread.php?t=134257732)

DustyPorViva 01-21-2010 09:28 AM

savexml/loadxml
 
Can anyone explain the var formatting that these two functions use? I couldn't figure out how to use savexml, so I created a template xml and used loadxml to echo it, and apparently it uses an array?

XML file:
PHP Code:

<?xml version="1.0"?>
<note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
</note>

temp.obj.loadxml("test.xml");
echo(obj);
PHP Code:

"""Tove,"",""Jani,"",""Reminder,"",""""""Don't forget me this weekend!"""",""", 

As you can see, it doesn't include the 'to', 'from' and so on. However, if I obj.savexml("test2.xml"), it maintains that format. I just don't know where and how it's storing it...

DustyPorViva 01-21-2010 09:57 AM

Okay, seems the format is:
obj[0].name = "note";
obj[0][0].name = "to";
obj[0][1].name = "from";
obj[0][2].name = "heading";
obj[0][3].name = "fbody";
obj[0][x][0] = "text"

So ya...

fowlplay4 01-21-2010 04:20 PM

can you not do..

echo(obj.note.to.value); ?

Immolate 01-21-2010 07:35 PM

Quote:

Originally Posted by fowlplay4 (Post 1551565)
can you not do..

echo(obj.note.to.value); ?

Doesn't seem like it when I tested it.

Admins 01-21-2010 08:08 PM

Generating xml:

PHP Code:

temp.xml = "";
with (temp.xml.addArrayMember("friends")) {
  for (
temp.pl: allplayers) {
    
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() >= 1 && temp.xml[0].name=="friends") {
  for (
temp.i=0; temp.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.


All times are GMT +2. The time now is 02:39 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.