24.03.2013, 22:53
(
Последний раз редактировалось steki.; 07.04.2013 в 18:46.
)
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.
from Here
And this code:
Will come with this on console:
Functions
Download
0.2 - Thousand bug fixes, several new functions
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>
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);
Код:
[19:52:32] XML:: (text.xml) XML File loaded [1] [19:52:32] name: Farmhouse Ale [19:52:32] XML:: XML File unloaded [1]
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
Source - GitHubChangelog:
Binary + Include - SolidFiles
0.2 - Thousand bug fixes, several new functions