How do I export array as XML

0 favourites
  • 6 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • 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

    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 !!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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 .

  • 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:

    <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>[/code:1p60ug27]
    
    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.
  • There is an XML builder and writer:

  • really nice find

    I'm totally overlooked this very useful rexrainbow plugin...rex_XMLWriter

    array

    "{""c2array"":true,""size"":[5,2,1],""data"":[[[""width""],[150]],[[""height""],[200]],[[""zi""],[3]],[[""dx""],[400]],[[""e""],[""true""]]]}"[/code:1cwliotr]
    to:
    [img="http://lookpic.com/O/i2/618/lOIPwhJu.png"]
    
    [url=https://app.box.com/s/3nmv5sg88or3q64wwrat61thq2bc0c7e]arrayXMLWriter.capx[/url]
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)