BASIC

Author Topic: Little TinyXml Wrapper :)  (Read 11091 times)

Offline backslider

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 892
    • View Profile
Little TinyXml Wrapper :)
« on: 2012-Mar-22 »
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 [Select]
// --------------------------------- //
// 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]
« Last Edit: 2012-Mar-28 by backslider »

MrTAToad

  • Guest
Re: Little TinyXml Wrapper :)
« Reply #1 on: 2012-Mar-22 »
Every so slight problem : Get a whole load of C compiler errors...

I presume you need the header package ?

Offline trucidare

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1377
  • Bachelor of Fail
    • View Profile
Re: Little TinyXml Wrapper :)
« Reply #2 on: 2012-Mar-22 »
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
MacBook Pro 2,2 GHz Core 2 Duo, 4 GB RAM, 160 GB HDD, 8600M GT
Core i3 - 3,07 GHz, 8 GB Ram, 2.5 TB HDD, Geforce GTX 260+ OC

Offline backslider

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 892
    • View Profile
Re: Little TinyXml Wrapper :)
« Reply #3 on: 2012-Mar-22 »
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! ;)

Offline backslider

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 892
    • View Profile
Re: Little TinyXml Wrapper :)
« Reply #4 on: 2012-Mar-23 »
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
« Last Edit: 2012-Mar-23 by backslider »

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4971
  • O Rly?
    • View Profile
Re: Little TinyXml Wrapper :)
« Reply #5 on: 2012-Mar-23 »
cool :D
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

MrTAToad

  • Guest
Re: Little TinyXml Wrapper :)
« Reply #6 on: 2012-Mar-23 »
Does Code::Blocks support Android compilng yet ?

Offline Wampus

  • Prof. Inline
  • *****
  • Posts: 1004
    • View Profile
Re: Little TinyXml Wrapper :)
« Reply #7 on: 2012-Mar-23 »
I'm get these errors when trying to compile (the updated download):-

Code: GLBasic [Select]
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:30:20: assert.h: No such file or directory
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:31:20: string.h: No such file or directory
In file included from C:\Users\Oil\AppData\Local\Temp\glbasic\gpc_temp1.cpp:14:
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:59: error: `size_t' does not name a type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:62: error: `size_type' does not name a type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:85: error: `size_type' has not been declared
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:85: error: ISO C++ forbids declaration of `len' with no type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:134: error: `size_type' does not name a type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:137: error: `size_type' does not name a type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:143: error: `size_type' does not name a type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:147: error: expected `;' before '(' token
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:154: error: expected `;' before "char"
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:154: error: declaration of `operator[]' as non-function
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:154: error: expected `;' before '(' token
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:161: error: expected `;' before "size_type"
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:161: error: `size_type' does not name a type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:167: error: `size_type' does not name a type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:191: error: `size_type' has not been declared
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:191: error: ISO C++ forbids declaration of `cap' with no type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:193: error: `size_type' has not been declared
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:193: error: ISO C++ forbids declaration of `len' with no type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:195: error: `size_type' has not been declared
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:195: error: ISO C++ forbids declaration of `len' with no type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:206: error: `size_type' has not been declared
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:206: error: ISO C++ forbids declaration of `sz' with no type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:207: error: `size_type' has not been declared
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:207: error: ISO C++ forbids declaration of `sz' with no type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:213: error: `size_type' does not name a type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:217: error: `size_type' has not been declared
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:217: error: `size_type' has not been declared
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:218: error: ISO C++ forbids declaration of `sz' with no type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:218: error: ISO C++ forbids declaration of `cap' with no type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h: In copy constructor `TiXmlString::TiXmlString(const TiXmlString&)':
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:73: error: 'const class TiXmlString' has no member named 'length'
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:74: error: `length' was not declared in this scope
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:74: error: `memcpy' was not declared in this scope
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h: In constructor `TiXmlString::TiXmlString(const char*)':
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:80: error: `size_type' has not been declared
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:80: error: `strlen' was not declared in this scope
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:81: error: `length' was not declared in this scope
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:81: error: `memcpy' was not declared in this scope
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h: In constructor `TiXmlString::TiXmlString(const char*, int)':
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:88: error: `memcpy' was not declared in this scope
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h: In member function `TiXmlString& TiXmlString::operator=(const char*)':
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:99: error: `size_type' was not declared in this scope
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h: In member function `TiXmlString& TiXmlString::operator=(const TiXmlString&)':
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:104: error: 'const class TiXmlString' has no member named 'length'
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h: In member function `TiXmlString& TiXmlString::operator+=(const char*)':
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:111: error: `size_type' has not been declared
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:111: error: `strlen' was not declared in this scope
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h: In member function `TiXmlString& TiXmlString::operator+=(const TiXmlString&)':
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:123: error: 'const class TiXmlString' has no member named 'length'
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h: In member function `bool TiXmlString::empty() const':
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:140: error: 'struct TiXmlString::Rep' has no member named 'size'
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h: In member function `void TiXmlString::set_size(int)':
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:207: error: 'struct TiXmlString::Rep' has no member named 'size'
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h: In member function `char* TiXmlString::finish() const':
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:209: error: 'struct TiXmlString::Rep' has no member named 'size'
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h: In member function `void TiXmlString::init(int, int)':
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:226: error: `size_type' does not name a type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:227: error: `size_type' does not name a type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:228: error: `intsNeeded' was not declared in this scope
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:230: error: 'struct TiXmlString::Rep' has no member named 'size'
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:231: error: 'struct TiXmlString::Rep' has no member named 'capacity'
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h: In function `bool operator==(const TiXmlString&, const TiXmlString&)':
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:257: error: 'const class TiXmlString' has no member named 'length'
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:257: error: 'const class TiXmlString' has no member named 'length'
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:258: error: `strcmp' was not declared in this scope
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h: In function `bool operator<(const TiXmlString&, const TiXmlString&)':
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:262: error: `strcmp' was not declared in this scope
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h: In function `bool operator==(const TiXmlString&, const char*)':
C:/tinyxml_wrapper/TinyXml/tinyxml/tinystr.h:270: error: `strcmp' was not declared in this scope
In file included from C:\Users\Oil\AppData\Local\Temp\glbasic\gpc_temp1.cpp:16:
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:35:19: ctype.h: No such file or directory
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:36:19: stdio.h: No such file or directory
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:37:20: stdlib.h: No such file or directory
In file included from C:\Users\Oil\AppData\Local\Temp\glbasic\gpc_temp1.cpp:16:
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h: At global scope:
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:213: error: `FILE' has not been declared
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:213: error: ISO C++ forbids declaration of `cfile' with no type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h: In static member function `static bool TiXmlBase::IsWhiteSpace(char)':
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:292: error: `isspace' was not declared in this scope
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h: In static member function `static const char* TiXmlBase::GetChar(const char*, char*, int*, TiXmlEncoding)':
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:329: error: `assert' was not declared in this scope
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h: In static member function `static int TiXmlBase::ToLower(int, TiXmlEncoding)':
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:386: error: `tolower' was not declared in this scope
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:391: error: `tolower' was not declared in this scope
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h: At global scope:
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:870: error: `FILE' has not been declared
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:870: error: ISO C++ forbids declaration of `cfile' with no type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:873: error: `FILE' has not been declared
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:873: error: ISO C++ forbids declaration of `cfile' with no type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:1126: error: `FILE' has not been declared
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:1126: error: ISO C++ forbids declaration of `cfile' with no type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:1179: error: `FILE' has not been declared
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:1179: error: ISO C++ forbids declaration of `cfile' with no type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:1240: error: `FILE' has not been declared
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:1240: error: ISO C++ forbids declaration of `cfile' with no type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:1318: error: `FILE' has not been declared
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:1318: error: ISO C++ forbids declaration of `cfile' with no type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:1319: error: `FILE' has not been declared
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:1319: error: ISO C++ forbids declaration of `cfile' with no type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:1366: error: `FILE' has not been declared
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:1366: error: ISO C++ forbids declaration of `cfile' with no type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:1427: error: `FILE' has not been declared
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:1427: error: ISO C++ forbids declaration of `parameter' with no type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:1429: error: `FILE' has not been declared
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:1429: error: ISO C++ forbids declaration of `parameter' with no type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:1528: error: `FILE' has not been declared
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:1528: error: ISO C++ forbids declaration of `cfile' with no type
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h: In member function `void TiXmlDocument::Print() const':
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:1519: error: `stdout' was not declared in this scope
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h: At global scope:
C:/tinyxml_wrapper/TinyXml/tinyxml/tinyxml.h:1777: error: `size_t' does not name a type

Offline backslider

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 892
    • View Profile
Re: Little TinyXml Wrapper :)
« Reply #8 on: 2012-Mar-25 »
Okay,

then I have to put all headers into the lib...
Tomorrow I will update it.

;)

Offline backslider

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 892
    • View Profile
Re: Little TinyXml Wrapper :)
« Reply #9 on: 2012-Mar-26 »
Hi again,

if you want to use the tinyXML wrapper you have to download the glbasic c++ headers!
But that should'nt be a problem for a developer. :P

Here is the link:
http://www.glbasic.com/files/headers.rar

You have to put the files into the compiler directory of the glbasic program folder.

cheers

MrTAToad

  • Guest
Re: Little TinyXml Wrapper :)
« Reply #10 on: 2012-Mar-27 »
They do really need updating :)

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3338
  • Integrated Brain
    • View Profile
Re: Little TinyXml Wrapper :)
« Reply #11 on: 2012-Mar-28 »
Hi for me works, but only in PC, this can be works in any platform...  :-[

This will be genial, if I don´t understtod bad, you can send data from any part to another... can send 3D files, from a mobile to a server not in a LAN

Offline backslider

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 892
    • View Profile
Re: Little TinyXml Wrapper :)
« Reply #12 on: 2012-Mar-28 »
Hi for me works, but only in PC, this can be works in any platform...  :-[

This will be genial, if I don´t understtod bad, you can send data from any part to another... can send 3D files, from a mobile to a server not in a LAN

Hi mentalthink,

I think you have to compile the static library (libTinyXml.a) with codeblocks on your target system.
If it compiles without error you will get a library in the codeblocks project folder.
Copy the lib to your glbasic project folder and overwrite the existing libTinyXml.a file.

Then try it again to compile the glbasic project.