27.05.2010, 17:57
(
Последний раз редактировалось Zeex; 26.10.2010 в 07:08.
)
A very basic plugin that allows you load XML documents and extract data from them using XPath expressions. It is based on pugixml parser/loader by Arseny Kapoulkine.
The following functions are provided:
Usage example
example_account.xml:
Downloads
The following functions are provided:
-
XML:xml_open(const filename[])
Load an XML document.
-
bool:xml_get_bool(XML:handle, const xpath[])
Evaluate the result of XPath query as boolean and return it.
-
xml_get_int(XML:handle, const xpath[])
Evaluate the result of XPath query as integer and return it.
-
Float:xml_get_float(XML:handle, const xpath[])
Evaluate the result of XPath query as floating point number and return it.
-
xml_get_string(XML:handle, const xpath[], result[], size = sizeof result)
Return the result of XPath query as string.
-
xml_close(XML:handle)
Delete the specified document from memory.
Usage example
pawn Код:
#include <xml>
// somewhere...
// Open file example_account.xml
new XML:xml = xml_open("example_account.xml");
// Check whether it was opened
if (xml)
{
new buf[100];
// Get some data...
xml_get_string(xml, "player/profile/sex", buf);
printf("sex=%s", buf);
printf("age=%d", xml_get_int(xml, "player/profile/age"));
printf("x pos=%f", xml_get_float(xml, "player/ingame/saved_position/x"));
printf("y pos=%f", xml_get_float(xml, "player/ingame/saved_position/y"));
printf("z pos=%f", xml_get_float(xml, "player/ingame/saved_position/z"));
xml_get_string(xml, "player/ingame/weapon[@ammo>100]/@name", buf);
printf(buf);
// Close when finished working
xml_close(xml);
}
Код:
<?xml version="1.0"?> <player> <profile> <password>asdf8s9ad7f2</password> <sex>male</sex> <age>18</age> </profile> <ingame> <saved_position> <x>123.456</x> <y>9871.8712</y> <z>3.000</z> </saved_position> <money>100000</money> <weapon name="Deagle" ammo="60" /> <weapon name="Minigun" ammo="5000" /> <weapon name="Chainsaw" ammo="0" /> </ingame> </player>