Sign in to follow this  

Unity Nice fast XML parsers with validation?

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



- Cross platform/Easy to port

- Fast



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

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();

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Announcements

  • Forum Statistics

    • Total Topics
    • Total Posts
  • Similar Content

    • By sveta_itseez3D
      itSeez3D, a leading developer of mobile 3d scanning software, announced today a new SDK for its automatic 3D avatar generation technology, Avatar SDK for Unity. The Avatar SDK for Unity is a robust plug-n-play toolset which enables developers and creatives to integrate realistic user-generated 3D avatars into their Unity-based applications. SDK users can allow players to create their own avatars in the application or integrate the SDK into their own production processes for character design and animation.
      “Virtual avatars have recently become increasingly popular, especially in sports games and social VR apps. With the advance of VR and AR, the demand to get humans into the digital world is only increasing”, said Victor Erukhimov, itSeez3D CEO. “Our new Avatar SDK for Unity makes it super-easy to bring the avatar technology into any Unity-based game or VR/AR experience. With the Avatar SDK for Unity now every developer can bring face scanning technology into their games and allow players to create their own personalized in-game avatars, making the gameplay much more exciting and immersive.”
      Key features of the Avatar SDK for Unity:
      Automatic generation of a color 3D face model from a single selfie photo in 5-10 seconds (!). Works best with selfies, but can be used with any portrait photo.
      Shape and texture of the head model are unique for each person, synthesized with a deep learning algorithm crafted by computer vision experts
      Head models support runtime blendshape facial animations (45 different expressions)
      Generated 3D heads include eyes, mouth, and teeth
      Algorithms synthesize 3D meshes in mid-poly resolution, ~12k vertices, and ~24k triangles
      Six predefined hairstyles with hair-recoloring feature (many more available on request)
      Avatar generation API can be used in design-time and in run-time, which means you can allow users to create their own avatars in your game
      Cloud version is cross-platform, and offline version currently works on PCs with 64-bit Windows (support for more platforms is coming soon)
      Well-documented samples showcasing the functionality.
      The Avatar SDK for Unity is offered in two modes - “Cloud” and “Offline”. The “Cloud” version is available at and the “Offline” version is available by request at
      About itSeez3D
      At itSeez3D, we are working on the computer vision technology that turns mobile devices into powerful 3D scanners. itSeez3D has developed the world's first mobile 3D scanning application that allows to create high-resolution photorealistic 3D models of people's' faces, bodies and objects. The application is available for iOS and Windows OS mobile devices powered with 3D cameras. In 2016 the company introduced Avatar SDK that creates a realistic 3D model of a face from a single selfie photo. To learn more about itSeez3D scanning software and 3D avatar creation technology, please visit and

      View full story
  • Popular Now