Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI-Nspire => Topic started by: SpiroH on September 11, 2012, 06:24:12 pm

Title: XML2TXT, XML2LUA, TXT2XML, LUA2XML and 2TNS
Post by: SpiroH on September 11, 2012, 06:24:12 pm
Hi, I've been playing around with the weird xml usage by TI. I'm not sure if what i'm going to present to you is of any interest to the programmers community in general but i've decided to do it, anyway. What started me with this type of thing was the need to quickly send a text document to the Nspire calculator, without having to use the tiny in-calc editor. So, i've looked around in omnimaga site and i found first the TNS2XML (http://tiplanet.org/forum/archives_voir.php?id=4885)  in-calc utility, which allows you to grab the xml content of a tns doc via a hook, without going thru the hassle of having to decrypt the tns (btw, a clever idea). That was my starting point, i could finally get hold of the xml content. But, alas, looking inside the xml, the text was not clear at all. So, how could you recover back the embedded text? It had to be there (hidden) somehow!? A second look into the xml and i've found some clues on how that could eventually be done. Well, i think i did it with my XML2TXT utility. Just drop a 'Problem.xml' on top of it, and in principle it should present you at the bottom window the embedded text inside the xml.
  (http://img442.imageshack.us/img442/971/1xml2txt.png)   (http://img833.imageshack.us/img833/5530/2xml2lua.png)

Secondly, what about the other way around? How on earth could we encode a text-file and send it the calc. We need to prepare an xml file that can be understood by the Nspire. Next, we need to encrypt and compress it, short make it a tns-doc file. Luckly, this latter step had already been accomplished via the 'luna' utility (link below). So, i was left with the task of transforming the text-file into a suitable xml format that could then be post-processed by the 'luna' utility to produce the final 'tns' doc. Now, we only need to send it to the calc and open it up. This brings me to my second utility TXT2XML, that does just that, it encodes the text-file into xml and with the help of 'luna' produces a 'tns' file, ready to be openned in-calc. After some more digging, i thought it would be interesting to do the same for 'lua' scripts. Here, the generated xml has different xml-elements. So i've adjusted both previous utilities to also handle the lua scripts.
  (http://img69.imageshack.us/img69/6480/3txt2xml.png)    (http://img827.imageshack.us/img827/228/4lua2xml.png)
To clear up a bit more the explanation, i emphasize the fact that the TXT2XML utility actually does a bit more than just the xml generation, it also creates the respective 'tns' files with the help of 'luna'.

You can download luna-v0.3a.zip here (http://www.unsads.com/projects/nsptools/downloader/download/release/3). To be able to generate 'tns' files, you'll need to extract the 2 files 'luna.exe' and 'libeay32.dll' and place both in the same directory as the 2 utilities TXT2XML and XML2TXT.

As already said above, i'm not sure if this can be useful for people, but at least for me it was fun to develop and use them with the nspire emulator. See if it suits you in any way. There may exist some compatbility issues, which i'll try to tackle later.

Enjoy,
SpiroH

P.S: I know this is rather basic stuff for many of you, but i think it can be helpful for newcomers to the nspire environment.



Title: Re: XML2TXT, XML2LUA, TXT2XML, LUA2XML and 2TNS
Post by: blfngl on September 11, 2012, 07:29:19 pm
Very nice! I can't wait to use it :)
Title: Re: XML2TXT, XML2LUA, TXT2XML, LUA2XML and 2TNS
Post by: ElementCoder on September 12, 2012, 05:54:54 am
This is definitely useful! Good job.
Title: Re: XML2TXT, XML2LUA, TXT2XML, LUA2XML and 2TNS
Post by: Adriweb on September 12, 2012, 06:27:24 am
Nice !

Although for Lua scripts the built-in editor is there for that :P (in TINCS 3.2, I mean)
But for people who don't have it, it's definitely a good job.

By the way, what language is this written in ? Any chance it would compile on other platform ?



EDIT : It looks like there are still some   "   chars here and there ?  (in the example lua file)
Title: Re: XML2TXT, XML2LUA, TXT2XML, LUA2XML and 2TNS
Post by: SpiroH on September 13, 2012, 06:20:43 pm
Thank you all for the nice remarks and excuse me for the late response.

By the way, what language is this written in ? Any chance it would compile on other platform ?
The language is c++. Well, it relies on windows IXMLDOMDocument interface, but it shouldn't too difficult to find some equivalent in the unix/mac-world. Right now, i don't have much time, but asap i'll try to split the GUI and make a simpler console app that should be easy enough to port. I'll see what i can do.

Quote from: adriweb
It looks like there are still some   "   chars here and there ?  (in the example lua file)
Thanks! Yeah, sorry about that. Hope is fixed now. Please check attachment.

Also, this was a first version to test the 'concept'. The previous problem was due to a weird escape-sequence not being detected in TXT2XML utility. It's possible that some others will surface with different lua scripts. We'll get them then. ;)  I've also added a 'save' button to the XML2TXT utility, so that the user can save the text/lua-script rather then use the clipboard.

Cheers,
Title: Re: XML2TXT, XML2LUA, TXT2XML, LUA2XML and 2TNS
Post by: Jonius7 on June 30, 2013, 01:57:19 am
Err, so what's 2TNS then?
This looks like a nifty set of tools that'll come in handy, nice work.