Reading and Writing XML files?

This forum is currently in read-only mode.
From the Asset Store
Convert multiple Excel files into JSON files and import them into construct3.
  • Is there a way to write and read XML files from a Construct application, and if so, what is the best way to go about this?

    To my knowledge there is no XML plugin, but it seems like python script might provide a roundabout means of handling XML files.

    I'm also considering building an XML add-on, as I believe I have all the necessary tools, although I'm not sure as of yet how much work would be involved.

    Any advice is welcome.

  • I've made a couple of XML parsers in Construct -- made one just last night, actually. I don't actually have an example on hand but I can give the general idea around my parsers.

    I usually use the ListBox object to load a file, then I use it's "For each line" event to read through the entire file. Inside the subevents to this event, you can read the file using tokens. To get the name of the tag on the current line, you'd this expression:

    GetToken(GetToken(ListBox.LineText(ListBox.CurrentIndex), 2, "<"), 1, ">")[/code:1vng6jel]
    And to get the contents of an element, you'd use this expression:
    
    [code:1vng6jel]GetToken(GetToken(ListBox.LineText(ListBox.CurrentIndex), 2, ">"), 1, "<")[/code:1vng6jel]
    Unfortunately, this only allows you to get the content of an element if your file is arranged like this:
    
    [code:1vng6jel]<tag>stuff</tag>[/code:1vng6jel]
    Instead of this:
    
    [code:1vng6jel]<tag>
        stuff
    </tag>[/code:1vng6jel]
    So, this method works, but it's pretty limited.  Hope that helps some, anyways.
  • I don't think there's any standards-compliant way to read or write XML files in Construct at the moment - it would certainly make for a useful plugin.

  • Sounds like Python might be well suited for this.

  • Thanks for the information. It looks like your method Linkman2004 is the best way to handle simple XML using events. With a little more code, it might even be able to handle more complicated XML, and so I may end up using a solution like that.

    That said, I'm curios as to whether I could use a third party python library for XML manipulation in Construct. I'm not overly familiar with the capabilities of Construct's python scripting system.

    As an alternative I'm still considering building an XML plugin, as it might be the easiest way to get standards compliant XML manipulation, and I would just like to start building plugins in general. My current thinking is that if there is an open source XML library that is suitably simple to work with, I might be able to drop that into a plugin, and then add some simple action/condition/expression code to make its features accessible from Construct.

    Granted, I've never built a plugin for Construct before, so if anyone has a recommendation for an XML library that might work, or an estimation as to how difficult the process of making it a plugin will be, I would appreciate the advice. Thanks again for the feedback.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • There's always TinyXML if you decide to make a plugin. It's small, open-source, and seems to be fairly popular.

    I don't know how accurate my estimation is, but I can't imagine it would be too hard to make a plugin using it. Once one gets used to it, the SDK is actually really simple to work with and the difficulty level starts boiling down more to ones own coding skills.

  • I'm fluent with parsers and have done some for XML before.

    I considered suggesting this but I have no idea on how would one store the resulting data. Hash table? can't put another hash table inside of one so :s

    Would have to be an XML object and you'd have to query it, could be a bit complex to use.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)