• Advertisement
Sign in to follow this  

Unity Nice fast XML parsers with validation?

This topic is 1123 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have this little cross platform UI framework I'm working on. 

It uses XML as layout definitions.

 

Currently, I'm using TinyXML since that is what we have always used, it's simple and fast, and I didn't need any advanced XML features.

Getting to it's limits now though, so I'm looking for nice alternatives, hoping the community can give some tips! smile.png

 

Must have features:

- C or C++ API (prefer fairly modern C++)

- Schema validation through DTD or XSD (anyone has anything to say about which of the two to prefer?)

- Good error handling, so I can output nice and readable error messages when people mess up their XML

- License to use for commercial closed source projects

 

Preferable:

- Cross platform/Easy to port

- Fast

- DOM

 

Wild wish:

- parsing/compiling binary XML (for speed and space savings)

 

 

If its easy to port and fast, I might be able to use it for parsing the XML on device (iOS, Android, WhateverOS), if not, it could be ok if I just run it in a tool on the desktop dev computer.

 

 

A quick search have turned up two alternatives:

Xerces-C++  (Seems dead though? last update on homepage is 2010...)

libxml2  (from Gnome)

 

 

Anyone who has any tips for other alternatives, or something to say about either of the  two above?

Edited by Olof Hedman

Share this post


Link to post
Share on other sites
Advertisement

I have recently ventured the same road as you did on my hobby project as it required a data binding compiler and a runtime XML parser (basically something similar to JAXB in java).

 

I have found that the problem with data binding and xml parsing in C++ is that most libraries offer fast and efficient xml parsing, however as soon as it must include vlidation mechanisms and data binding mechanisms, the libraries get a lot bigger.

 

I chose Code Synthesis XSD which offers all of your requirements (compiler to create classes from XSD file, runtime XML validation and parsing ...) and is released under GPLv2 licence.

It has indirect 3rd party requirement to Xerces-C++ to compile it though.

As for speed I cannot answer yet as I have been only using it for a few days.

 

The nice think about it is, it is nicely integrate-able with VS, as it can recompile your data binding classes on each build and with different options (wchar length, c++11 compiler ....)

File size on my setup (VS2013, x86, MDd runtime): 3MB lib, 4MB dll for debug and 3MB lib and 2MB dll for release build.

 

To provide a small sample of usage (classes have already been generated by the xsd compiler by providing it with the XSD schema).


std::unique_ptr<bridge_configuration> bridgeConfiguration = bridge_configuration_(CONFIGURATION_FILE, xml_schema::flags::dont_validate); 
//To parse the XML.
 for (bridge_sockets::bridge_socket_iterator it(bridgeConfiguration->bridge_sockets().bridge_socket().begin());
             it != bridgeConfiguration->bridge_sockets().bridge_socket().end(); 
//This is a bit clunky, maybe I don't know how to use it yet....... :(
             ++it) {
            if (bridge_socket::name_optional("frontend") == it->type()) {
                frontEndSocketAddress = it->protocol()->data();
                frontEndSocketAddress.append(it->name()->data());
...

Do check their website though, they provide quite a nice description of the features. smile.png

Share this post


Link to post
Share on other sites

- Schema validation through DTD or XSD (anyone has anything to say about which of the two to prefer?)

DTD is more or less obsolete, stick to XSD.

 

Why do you not use some kind of resource packaging tool/pipeline ? This way you could validate all the xml files during the packaging process (e.g use a simple java tool to validate the xml against the xsd, java has out-of-the-box xml support) and you would use some kind of compression (zip) to avoid the support of binary xml.

Edited by Ashaman73

Share this post


Link to post
Share on other sites


I chose Code Synthesis XSD 

 

Thanks for the tip, it looks interesting. Probably a bit overkill for my needs right now though, but I definitely will remember it for if/when I need it.

 


Why do you not use some kind of resource packaging tool/pipeline ?

 

This might be the way to go, I was looking into C++ API:s since I like C++, and I wanted to build it into a bigger system, and also for the possible option of using it on device too.

But maybe the easiest is to just have a small xml verification tool in Java and pass any layout xml files through that before packaging it.

Also has the advantage of lots of documentation and examples...

 

Zip is probaby good enough compression, even though some binaryfication of the file first should make it even smaller, but that is not a critical need, just a wild wish :)

 

Thanks for the answers.

 

Just out of curiosity, anyone who have used either Xerces or libxml2 and have some opinion on how horrible/nice they are to use? :)

 

Also happy to receive any more xml validation tips if anyone care to share.

My main need right now is validation with good error messages that pinpoint the actual problem in malformed layout xml files.

Share this post


Link to post
Share on other sites

I think that "validation" and either "nice" or "fast" are mutually exclusive.

 

Do you really need validation in that part, though? Since you are in control of generating the XML (UI layout editor), you should be able to ensure that the document is created in a well-formed and, well... valid (according to your DTD/XSD) way.

 

If you are a little paranoid (that is, you don't trust yourself writing a correct generator), you can use any not-so-pretty-not-so-fast parser inside the UI layout editor to read in the document immediately after writing it out.

If that passes, then your nice-and-fast non-validating parser that you use everywhere and for which you've already written tons of code (code that works and has been tested) will be mighty fine to read it (after all, the document is valid and that doesn't change, so there's no need to check that over and over again).

If it doesn't pass, you need to fix the layout editor until valid documents come out, but there's no point validating the known-to-be-broken document on the user end anyway.

Edited by samoth

Share this post


Link to post
Share on other sites


I think that "validation" and either "nice" or "fast" are mutually exclusive.

 

That is probably true :)

Easy to set up and use is more important then fast, seems my thought to run it on device too isn't very practical.

TinyXML should be fine there.

 


Do you really need validation in that part, though?

 

For the time being, there will be no editor, they will be edited by programmers by hand.

It is brief and compact XML, designed to be easily human readable.

 

So some syntax checking in the tool pipeline would make life much easier when you forget some slash or quote somewhere or misspell a tag or attribute.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Tags

  • Advertisement
  • Popular Now

  • Similar Content

    • By NfiniT
      Hello!  Our team is a searching for a 2D Artist looking to add a title (whether the first one, or one of many) to his portfolio, with the opportunity to pursue a long-term partnership.
       
      Position & Responsibilities:
      Our team is looking for a 2D Artist to help produce finalized art assets from our current concepts and help finish our current working prototype.  This includes various stylized cartoon characters, level components/objects, background art, and possible UI elements.  The entire team can either provide you the concept art, or let you have extended creative freedom, it's up to you--whichever you feel is better suited for your process.
      Also, although this is not a requirement, if you want to expand your skill-base, you can dabble in the other aspects as well, be it animation, programming, design, narrative, etc.
      Project Description:
      Our project is titled Stanley and the Clocktower Caper, and is a casual 2D platformer with a puzzle element and child-friendly combat.  Our goal is a funny, relaxing experience that intentionally does not take itself seriously.
      Set in the steam-punk styled town, our protagonist Stanley (a sloth), is a local tinkerer and keeper of the town's clocktower.  The town and clocktower have been invaded (story-related reasoning) and are swarming with spiders who've gummed up the cogs with webs, removed gears and all-around caused chaos.  Stanley must make his way down, out of the clocktower, which will require unclogging gears, finding missing pieces to levers, switches, gear-trains, etc.  While all of this is a tall order, thankfully Stanley is an avid consumer of Slothbux, a particularly caffeinated brand of coffee which gives Stanley quite the pick-me-up (how else do you think a sloth manages to be a tinkerer and get so many odd things done!? ) and allows him to accomplish some feats of speed, agility and strength not normally attainable otherwise!
      This game will consist of Stanley escaping the tower, which is apparently going to be a pretty big tower for such a little sloth!  It must have a lot of clocks...  Pending good reception on release (this is discussed below), we would happily consider a follow-up adventure.
      Release & Other Business Stuff:
      We'll be releasing on PC, and are targeting a July release--it is an admittedly small window, but a lot of the functionality already exists and we've got a realistic perception of what we're capable of as a small team and have kept the scope of our project focused accordingly.  Distribution channel is not finalized, though the most obvious and likely candidates are Steam and Itch.io.  Price-point of the final product is TBD.
      You will be included in the rev-share, and of course that's regardless of whether you fill the role and leave or decide to stay with us for future titles.
      Team:
      There are currently four of us, you will be the fifth.
      1) (Me) Our resident programmer, and dabble in both concept art & Design. 
      2) Our producer (handles scheduling, keeping things organized and on task), who also handles animation & dabbles in design.
      3) Our lead designer (story, level layout, etc.), who also does a bit of concept art
      4) Our sound engineer, who is also using the opportunity to learn a bit of programming.
      Links to Stuff:
      Working prototype--https://iconoclast209.itch.io/stanley
       
      If you would like to fill the role or have more questions, feel free to reach out to me on PM or on Discord at Bryant - NfiniT#5890 
      Thank you for your time!
    • By revolverolver
      Aloha,
      First time working in 3D. Not as difficult as I thought it would be although I am pretty much a complete beginner in Blender. I chose the low poly style because I like how it looks and it is a lot easier than trying to make it look realistic.
      The gameplay is pretty much all physics driven which makes it feel satisfying to play. If it looks any fun then please check it out. I could really use a review or two.
      Here are some promo codes so that you don't have to pay a dime to download it: 
      PJW7MTMWL3W3
      A4JLYRPTXMJH
      AXRKPMAT7AAY
      YMFJPTPJ9EX3
      JY3W6FNKTM6L
       
      App store link: https://itunes.apple.com/us/app/flip-trickster/id1351027839?l=en&mt=8
       
       
    • By Innoc uous
      I'm working on a space game, and I suck at art. I would love to get some help from someone who is more skilled than me. Things I need include modular space ship parts and GUI elements. Nothing too fancy, just functional so I can get a prototype put together. This could potentially become a serious project, but for now this is just a hobby project.
       
      In this video, you can see a few things I already completed
      :2018-02-24 20-08-13.flv2018-02-24 20-08-13.flv
    • By Innoc uous
      If you want to incorporate noise into your shaders, the Turbulance Library has you covered. Using code I gathered from this library, I made a cginc file that contains all you need to easily implement noise into your unity shaders. Who knows how this stuff works, but man, does it work well!
       
      https://pastebin.com/LLCUpJut
       
      Here is an example of what you can create using these noise functions.
       
    • By Nio Martinez
      I'll be buying a new laptop as my workstation for building games, Mostly 3D but not hard core. 
       
      I'm stuck at choosing between these 2 specs below. Does this really matter and if so, can some one tell my how and why it matters. 
      Choice1:
      Intel core i5-8250U (8th gen Kabylake refresh)(6 MB Smart Cache, 1.6 GHz Base with Turbo Boost up to 3.4 GHz) 4 cores 8 threads
      RAM 8 GB DDR4 (2400 MHz)
      GPU 2 GB DDR5 Nvidia MX150 256 bit
      SSD: yes
      Choice2:
      Intel core i7-7500U 2.70GHz Base Processor (4M Cache, up to 3.50 GHz Boost) 2 Cores, 4 Threads
      RAM 4 GB DDR4 (1800 MHz)
      GPU 2 GB DDR5 Nvidia GeForce 940MX 256 bit
      SSD: No
       
  • Advertisement