[Plugin] [REL] XML loader
#1

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:
  • 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);
}
example_account.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>
Downloads
Reply
#2

Nice work, I might try it out, but I don't know what I can use it for. Any ideas?
Reply
#3

Excellent! I'm going to be able to use this as an RSS feed in-game.

Nice work!
Reply
#4

Sweet
Reply
#5

Quote:
Originally Posted by [03
Garsino ]
Nice work, I might try it out, but I don't know what I can use it for. Any ideas?
Added example, see the first post
Reply
#6

Quote:
Originally Posted by Zeex
Quote:
Originally Posted by [03
Garsino ]
Nice work, I might try it out, but I don't know what I can use it for. Any ideas?
Added example, see the first post
O, very nice
Reply
#7

Brilliant!
Reply
#8

Awesome work, good job!
Reply
#9

Amazing release man.
Reply
#10

Actually, I get an error that a .dll is missing from my computer when I start my samp-server with the plugin.
Reply
#11

Quote:
Originally Posted by lolumadd
Actually, I get an error that a .dll is missing from my computer when I start my samp-server with the plugin.
What's the text of error you are getting? If the server says "Failed" when trying to load it make sure you copied .dll to server_folder/plugins/ and added it to server.cfg
Reply
#12

Looks great, will be very useful if people want to retrieve character information from the XML file and display the info via PHP, I'm going to have to try everything out
Reply
#13

Now there's JSON and XML plugins/includes, awesome.
Reply
#14

Quote:
Originally Posted by Zeex
Quote:
Originally Posted by lolumadd
Actually, I get an error that a .dll is missing from my computer when I start my samp-server with the plugin.
What's the text of error you are getting? If the server says "Failed" when trying to load it make sure you copied .dll to server_folder/plugins/ and added it to server.cfg
The program can't start because MSVCR100.dll is missing from your computer. Try reinstalling the program to fix this problem.
Reply
#15

Awesome work there
Reply
#16

OMG, this is really, really awesome Zeex!
Reply
#17

Quote:
Originally Posted by lolumadd
Quote:
Originally Posted by Zeex
Quote:
Originally Posted by lolumadd
Actually, I get an error that a .dll is missing from my computer when I start my samp-server with the plugin.
What's the text of error you are getting? If the server says "Failed" when trying to load it make sure you copied .dll to server_folder/plugins/ and added it to server.cfg
The program can't start because MSVCR100.dll is missing from your computer. Try reinstalling the program to fix this problem.
OK, I compiled it with statically linked CRT and tested on another PC which has no MSVCR100.dll, re-download please and let me know is it alright
Reply
#18

nice job

не будет глючить с слишком длинными XML?
Reply
#19

Very useful plugin, nice release Zeek
Reply
#20

Quote:
Originally Posted by Zeex
Quote:
Originally Posted by lolumadd
Quote:
Originally Posted by Zeex
Quote:
Originally Posted by lolumadd
Actually, I get an error that a .dll is missing from my computer when I start my samp-server with the plugin.
What's the text of error you are getting? If the server says "Failed" when trying to load it make sure you copied .dll to server_folder/plugins/ and added it to server.cfg
The program can't start because MSVCR100.dll is missing from your computer. Try reinstalling the program to fix this problem.
OK, I compiled it with statically linked CRT and tested on another PC which has no MSVCR100.dll, re-download please and let me know is it alright
Thanks it works now! Anyways, would using .xml be any faster than using a .cfg and using file functions?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)