[Plugin] [REL] XML Plugin
#1

XML Plugin
Recently, I felt the need of a good XML parser plugin, so I made my own one.
I'm relatively new to C++ and tried to come with a good solution on handling XML data, nodes and attributes.
The plugin is based on rapidxml library.

How to
The plugin itself is based around 'pointers', which should be named as handlers.
You create one, navigate through the file with it and get the data which the 'pointer' points to.

Let's see an example of the following XML and Pawn code.
Код HTML:
<?xml version="1.0" encoding="utf-8"?>
<MyBeerJournal>
    <Brewery name="Founders Brewing Company" location="Grand Rapids, MI">
        <Beer name="Centennial" description="IPA" rating="A+" dateSampled="01/02/2011">
            "What an excellent IPA. This is the most delicious beer I have ever tasted!"
        </Beer>
    </Brewery>
    <Brewery name="Brewery Vivant" location="Grand Rapids, MI">
        <Beer name="Farmhouse Ale" description="Belgian Ale" rating="B" dateSampled="02/07/2015">
            This beer is not so good... but I am not that big of a fan of english style ales.
        </Beer>
    </Brewery>
    <Brewery name="Bells Brewery" location="Kalamazoo, MI">
        <Beer name="Two Hearted Ale" description="IPA" rating="A" dateSampled="03/15/2012">
            Another execllent brew. Two Hearted gives Founders Centennial a run for it's money.
        </Beer>
    </Brewery>
</MyBeerJournal>
from Here

And this code:
pawn Код:
new XMLFile:xml = xml_open("text.xml");
new XMLPointer:pointer = xml_pointer(xml);
xml_pointer_childnode(pointer, "MyBeerJournal");
xml_pointer_childnode(pointer, "Brewery");
xml_pointer_nextnode(pointer);
xml_pointer_childnode(pointer);
xml_pointer_parentnode(pointer);
xml_pointer_attr(pointer);
new tmp[1000], tmp2[1000];
xml_pointer_getname(pointer, tmp);
xml_pointer_getvalue(pointer, tmp2);
printf("%s: %s", tmp, tmp2);

xml_killpointer(pointer);
xml_close(xml);
Will come with this on console:
Код:
[19:52:32] XML:: (text.xml) XML File loaded [1]
[19:52:32] name: Farmhouse Ale
[19:52:32] XML:: XML File unloaded [1]
Functions
pawn Код:
native XMLFile:xml_open(input[]); // Opens a file
native xml_close(XMLFile:file); // Closes a file
native xml_save(XMLFile:file); // Saves a file

native XMLPointer:xml_pointer(XMLFile:file); // Creates a pointer and points it to document
native XMLPointer:xml_clonepointer(XMLPointer:pointer); // Creates a new pointer based on existing pointer
native xml_killpointer(XMLPointer:pointer); // Destroys a pointer

native xml_pointer_getfilehandle(XMLPointer:pointer); // Gets file handle from pointer
native xml_pointer_getname(XMLPointer:pointer, name[], len = sizeof(name)); // Gets the node/attribute name from given pointer
native xml_pointer_getvalue(XMLPointer:pointer, value[], len = sizeof(value)); // Gets node/attribute value from given pointer
native xml_pointer_getvalue_int(XMLPointer:pointer); // Gets node/attribute value as an int
native xml_pointer_getvalue_float(XMLPointer:pointer); // Gets node/attribute value as a float

native xml_pointer_root(XMLPointer:pointer); // Points pointer to document root
native xml_pointer_childnode(XMLPointer:pointer, node[] = ""); // Points pointer to child node, specifying or not a node name
native xml_pointer_nextnode(XMLPointer:pointer, node[] = ""); // Points pointer to next node at the same height, specifying or not a node name
native xml_pointer_parentnode(XMLPointer:pointer); // Points pointer to parent node, being the pointer currently a node or an attribute
native xml_pointer_childattr(XMLPointer:pointer, attr[] = ""); // Points pointer to a child node
native xml_pointer_nextattr(XMLPointer:pointer, attr[] = ""); // Points pointer to next attribute

native xml_pointer_delete(XMLPointer:pointer); // Delete element pointed by the pointer. Current pointer gets pointed to parent node, or document root
native xml_pointer_appendnode(XMLPointer:pointer, name[], value[]=""); // Appends a child node to current pointer node
native xml_pointer_prependnode(XMLPointer:pointer, name[], value[]=""); // Prepends a child node to current pointer node
Download
Source - GitHub
Binary + Include - SolidFiles
Changelog:
0.2 - Thousand bug fixes, several new functions
Reply
#2

Sexy.
Reply
#3

Very Nice
Reply
#4

You being a newbie, this is so good! :P

You could do a json plugin too :P
Reply
#5

cute ;o and nice work
Reply
#6

Quote:
Originally Posted by BlueX
Посмотреть сообщение
Very Nice
Sexy.
Reply
#7

There's no need for this plugin if you're using YSI.
Reply
#8

There's no need for YSI if you're using this plugin.
Reply
#9

Quote:
Originally Posted by Stewie`
Посмотреть сообщение
There's no need for YSI if you're using this plugin.
Did you even read what you just wrote?
Reply
#10

Quote:
Originally Posted by Stewie`
Посмотреть сообщение
There's no need for YSI if you're using this plugin.
Reply
#11

Quote:
Originally Posted by Stewie`
View Post
There's no need for YSI if you're using this plugin.
But what about other things in YSI Library? I can't live without them
About thread, good work ^_^
Reply
#12

Well. Use it, or just don't. Not everyone is YSI dependant and believe me: This one is way faster.
Reply
#13

what does xml do ?
Reply
#14

Quote:
Originally Posted by Stewie`
View Post
There's no need for YSI if you're using this plugin.
What are you trying to prove here? Your XML plugin is superior?

Y_Less spent hundreds, if not, thousands of hours coding YSI. And you don't even know what it is? YSI is dozens of libraries going up and beyond XML... pfft.

****** it, and try using it.

Quote:
Originally Posted by Stewie`
View Post
Well. Use it, or just don't. Not everyone is YSI dependant and believe me: This one is way faster.
Why should I believe you? You're all full of yourself and stuck-up. You have no respect for YSI or its creator, do you?

Please, for the sake of my sanity:


PROVE IT
Reply
#15

Quote:
Originally Posted by Schurman
View Post
What are you trying to prove here? Your XML plugin is superior?

Y_Less spent hundreds, if not, thousands of hours coding YSI. And you don't even know what it is? YSI is dozens of libraries going up and beyond XML... pfft.

****** it, and try using it.



Why should I believe you? You're all full of yourself and stuck-up. You have no respect for YSI or its creator, do you?

Please, for the sake of my sanity:


PROVE IT
I'm not bullshitting here, and my job was quite simple and futile - create an interface from a great and fast xml parser to a scripting language with no object orientation support. I'm talking about software interface layering, and not the best algorithm. Or you dare to tell me a pawn script, which is executed by opcodes and native amx functions, passing through dozens of instructions is faster than C++ code compiled to native instructions?

See a nice speed test:


Add a little abstract machine overhead and there you go.

And about this one:
Quote:

There's no need for YSI if you're using this plugin.

Watch your interpretation: I meant if you're looking for a xml parser and that's it, that's it.

I have enough respect for Y_Less and I bet he is alright for what has been said here.
Let's keep the argument straight and not turn my topic into a flame war.
Reply
#16

Quote:
Originally Posted by Stewie`
View Post
I'm not bullshitting here, and my job was quite simple and futile - create an interface from a great and fast xml parser to a scripting language with no object orientation support. I'm talking about software interface layering, and not the best algorithm. Or you dare to tell me a pawn script, which is executed by opcodes and native amx functions, passing through dozens of instructions is faster than C++ code compiled to native instructions?

See a nice speed test:


Add a little abstract machine overhead and there you go.

And about this one:

Watch your interpretation: I meant if you're looking for a xml parser and that's it, that's it.

I have enough respect for Y_Less and I bet he is alright for what has been said here.
Let's keep the argument straight and not turn my topic into a flame war.
Thanks for this.

Can you post the code you used to test this so I can run the test myself?
Reply
#17

Plugin updated. - 0.2
Bug fixes and new functions to manipulate the XML File. More coming soon with examples.
Reply
#18

Very good, particularly unaware of the existence of this plugin or at least you had created one.
Reply
#19

Nicely done.

Could you make this support XPath expressions as well?
Reply
#20

That is possible, but it would require an workaround, like parse XML data, load with XPath, get the data from the path, parse again with rapidxml and get multiple data somehow.

Forgot to commit + update with new version with append and preppend attributes. Gonna do that in 30.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)