How do I SAVE/ UPDATE xml in Construct 2?

Get help using Construct 2

Post » Mon Jul 11, 2016 3:50 pm

Hello,

What is the best way to append data into XML in Construct 2 and Load it back?
My Construct 2 application will generate XML file daily based on user inputs and user will be able to load the xml data.

It is simply READ and WRITE method.

Thanks for any information.

Regards,
B
23
S
6
G
3
Posts: 39
Reputation: 4,759

Post » Mon Jul 11, 2016 4:07 pm

You may want to read THIS

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
83
S
34
G
40
Posts: 3,032
Reputation: 30,474

Post » Mon Jul 11, 2016 4:45 pm

Thanks Sol. I need an example within Construct 2.
B
23
S
6
G
3
Posts: 39
Reputation: 4,759

Post » Tue Jul 12, 2016 2:34 am

Sadly I've never worked directly with XML in C2 so a manual reference was all I had, sorry. Maybe someone else will have more info.

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
83
S
34
G
40
Posts: 3,032
Reputation: 30,474

Post » Tue Jul 12, 2016 3:13 am

Can the Construct 2 Genius Ashley able to help this?
B
23
S
6
G
3
Posts: 39
Reputation: 4,759

Post » Tue Jul 12, 2016 3:23 am

The xml plugin only reads xml, it doesn't write.
To write you'll need to either make your own writer or try to utilize some javascript library to do it.

You can look here for the xml file format:
https://en.wikipedia.org/wiki/XML


So basically the best way to append data to an xml file is to load it with ajax or with nwjs, store it in a variable, then just add text to the end.

As an example, if you have a file called "animal.xml" added to your project you can load it, append data to it, and finally download it with this:

start of layout
--- ajax: request animal.xml

global text xml=""

ajax: on loaded
--- set xml to ajax.lastdata
--- add "<fish>tuna</fish>" to xml
--- browser: invoke download of xml
B
92
S
32
G
109
Posts: 5,290
Reputation: 70,991

Post » Fri Jul 15, 2016 3:49 pm

You have to use server side code to write XML (or any) file. Only server side code contained in a secure environment is adequately trusted to have write privileges on a computer.

If you don't mind asking the user to save the XML, you can do what R0j0 suggests with the file download invoker.
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,418
Reputation: 4,830


Return to How do I....?

Who is online

Users browsing this forum: adventurist and 22 guests