How do I export array as XML

Get help using Construct 2

Post » Wed May 04, 2016 9:00 am

Hello all, recently returned to Construct and I need to make prototype of one simple database like system, I know construct may not be the best place where to make it, but it was actually asked to be done here :D

So The problem is I have several 2d arrays I need to export as XML, I know they can be exported as json files, but I need XML, is there any simple way to do it ?
I did search a little and only found some posts about loading xml, not downloading it.
All I need is to be able with clicking button to download xml version of array (much like when downloading json) to local storage.

Xmls dont need to be complicated, just basic stuff, so they can be actually imported in another system (not my problem what happens at their end as far as I can get something what can be exported)

Thanks !! ;)
B
3
Posts: 8
Reputation: 193

Post » Wed May 04, 2016 9:25 am

I'm puzzled by this question.
C2 offers JSON as "export" data format, but not XML.

In the absolute though, you could build your own XML file out of an array, but you have to implement it all in order to do so.

You have to first check the array's dimensions to determine whether it is a one, two or three dimension(s) array.
You have then go through each X, Y and Z of the array as required, and save tags/values for each cell.

You can save all this in a text variable and display it in a TextBox.
Unfortunately, I doubt you will be able to offer it for download, like a JSON file since this action (Download XML) is not available.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
289
S
112
G
94
Posts: 7,333
Reputation: 69,293

Post » Wed May 04, 2016 10:43 am

I do not know much abount construct, but Yes I started this converting process, was just wondering maybe there already is some kind of plugin or something what could make it easier. As far as I can somehow download text file with string (Xml code) I guess it will be fine .
B
3
Posts: 8
Reputation: 193

Post » Wed May 04, 2016 10:43 am

@Mr1H
I've done this in C2. It's not especially difficult, just plan out your XML schema so that certain X/Y coordinates are used for different values in the XML.

For example, this is my format for weapon settings:
Code: Select all
<weapon>
        <playerWeaponID>pistol</playerWeaponID>
        <playerWeaponName>Pistol</playerWeaponName>
        <playerAmmo>6</playerAmmo>
        <playerAmmoMax>6</playerAmmoMax>
        <projectileCount>1</projectileCount>
        <projectileSpeed>1400</projectileSpeed>
        <projectileRotation>0</projectileRotation>
        <projectileGravity>0</projectileGravity>
        <projectileLife>1.25</projectileLife>
        <projectileFireRate>0.325</projectileFireRate>
        <projectileExplode>0</projectileExplode>
        <projectileBounce>0</projectileBounce>
        <projectileTrail>1</projectileTrail>
        <projectileVFX>0</projectileVFX>
        <projectileSFX>revolver_fire_01</projectileSFX>
        <projectileBounceSFX>ricochet_01</projectileBounceSFX>
        <projectileHitSFX>cartoon_punch_01</projectileHitSFX>
</weapon>


WeaponID is from 0, Y. WeaponName is in 1, Y, etc. Implementing it as a function that loops through all of an array's rows/columns is fairly straightforward if you plan ahead.

@Kyatric
Of course the file can be downloaded. It's just a text file. Invoke a download of the resulting string with the Browser object. It's a pretty good way to save user settings locally as well.
B
77
S
43
G
24
Posts: 525
Reputation: 20,580

Post » Wed May 04, 2016 12:06 pm

B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed May 04, 2016 1:32 pm

really nice find @99Instances2Go...
I'm totally overlooked this very useful @rexrainbow plugin...rex_XMLWriter

array
Code: Select all
"{""c2array"":true,""size"":[5,2,1],""data"":[[[""width""],[150]],[[""height""],[200]],[[""zi""],[3]],[[""dx""],[400]],[[""e""],[""true""]]]}"

to:
Image

arrayXMLWriter.capx
Image
B
65
S
23
G
7
Posts: 1,505
Reputation: 10,896


Return to How do I....?

Who is online

Users browsing this forum: tarek2 and 9 guests