Codesnippets > Inline / 3rd party

Little TinyXml Wrapper :)

(1/3) > >>

backslider:
Hi guys,

I wrote a little TinyXML wrapper for GLBasic and I hope sb. of you will find it useful. :)

It has the following features implemented:

* load xml document
* create new xml document
* save xml document
* add a root element
* add child elements into elements
* add / set element attributes
* get first child element
* get element attributes as string
* add comments
This is the example code:

--- Code: GLBasic ---// --------------------------------- //
// Project: tinyxml_wrapper
// Start: Thursday, March 22, 2012
// IDE Version: 10.202


SETCURRENTDIR("Media") // go to media files

//1. create a new or load an existing xml document
LOCAL xmlDoc% = TiXml_CreateXmlDocument() //or TiXml_LoadXmlDocument("testNew.xml")

//2. add a comment if you want^^
TiXml_AddComment(xmlDoc, "Haha, this is a comment about nothing!")

//3. create the root element
LOCAL xmlElement% = TiXml_CreateElement("GLBasicRoot")
TiXml_SetAttribute(xmlElement, "Attribute 1", "IS")
TiXml_SetAttribute(xmlElement, "Attribute 2", "VERY")
TiXml_SetAttribute(xmlElement, "Attribute 3", "NICE!")

//4. create a child element
LOCAL childElement% = TiXml_CreateElement("GLBasicChild")
TiXml_SetAttribute(childElement, "Childattr 1", "Eat")
TiXml_SetAttribute(childElement, "Childattr 2", "My")
TiXml_SetAttribute(childElement, "Childattr 3", "Shorts :)")
TiXml_AddChildElement(xmlElement, childElement)

//5. add the child to the parent element
TiXml_AddRootElement(xmlDoc, xmlElement)

//6. now you can get elements by name and get their attributes
LOCAL firstChildElement% = TiXml_GetFirstChildElement(xmlElement, "GLBasicChild")
LOCAL attribute$ = TiXml_GetElementAttribute$(firstChildElement, "Childattr 2")
DEBUG attribute$ + "\n"

//7. save your xml document
TiXml_SaveXmlDocument(xmlDoc, "testNew.xml")
 
You need the GLBasic C++ header files to use this library! You can download it here:
http://www.glbasic.com/files/headers.rar

If you like it, use it!
And if you want you could add me to the credits :D

If you have any suggestions or your own cool functions, tell me and I will add it to the source! :)

Cheers

[attachment deleted by admin]

MrTAToad:
Every so slight problem : Get a whole load of C compiler errors...

I presume you need the header package ?

trucidare:
Owle - you need to make a static lib for this - make a static lib and use import "C" so everyone could use this - compile for linux, win, mac, android and everyone is happy

backslider:
Yes, you need the headers. They should be installed by default :D ok, I will create a lib version for all systems in the next time! ;)

backslider:
Okay guys,

I updated the project in the first post.
The TinyXml Gbas file is the same but now the code is using a static lib, so you don't need the c++ headers for GLBasic!
If it does'nt run, please post the error-code!

I included the CodeBlocks project. That means you can open it on each OS e.g. Linux in CodeBlocks and compile the lib with one click ("Build").
If you need help -> ask! ;)

Cheers

Navigation

[0] Message Index

[#] Next page

Go to full version