Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / XML Parser for AGK v.2

Author
Message
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 4th Mar 2017 22:56 Edited at: 4th Mar 2017 22:56
While working on my updated TMX loader, I had to revisit my XML parser. After greatly improving the speed over my previous Base64 code, the XML parsing turned out to be another major bottleneck in my loader. I'm happy to say the speed improvement makes this very usable now.

If you've used my old parser, which I'm just now realizing it appears I never posted my AppGameKit adaptation from my old DBP code, this one works entirely different. My old version required you to grab the values you wanted from the XML in a linear fashion as it read the document. So you took what data from the file you needed as it loaded line by line. Basically, it was more like a SAX parser. My new, entirely rewritten from scratch, approach is more like a DOM parser. While that does require more memory because the entire document is loaded in a tree-like structure, data from the XML-tree can be accessed at any time and maintains the integrity of the dom structure.

Attached is a TMX map file which contains a 120k character string making up the encoded base64 map data. This enormous string was the cause of major headaches in my old parser. The file itself is about 400 lines. Load time is virtually instant. Testing the code with my unencoded zelda map file, which is 867KB and 45,455 lines of text, it loaded in 1.4 seconds. (the old version took 2 minutes!)

In my example, the print element function is recursive as to print each element's children in a tabbed-structure so you can visualize the tree structure.
The element's structure as printed is the element's global id (it's index in the XML_Element array) followed by the element's tag name, the attributes listed in square brackets, then finally how many children this element contains and who it's parent is.

The function list is not yet complete, but should be well enough to show how it works. This also makes it very easy to write an XML writer as well.

One final thing to note is a slight limitation. The loader was written to assume only 1 tag is present per line. For most well-structured xml files, this shouldn't be an issue. However, something you download from the web may not be so neatly formatted, such as a result from an xml-rpc server request. Hopefully, in the future I can fix that limitation. But for now it is what it is and it serves its primary purpose I had intended, to read TMX files.


"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-03-19 11:08:54
Your offset time is: 2024-03-19 11:08:54