XmlLite: A Small And Fast XML Parser For Native C++

Sorry for the lack of posts lately – I’ve been hard at work on various projects. In particular I’ve been working on a whole bunch of new articles that will be published throughout the year. The first of these is available now in the April 2007 issue of MSDN Magazine.

XmlLite: A Small And Fast XML Parser For Native C++

Despite the ongoing success of the .NET Framework, Microsoft is still serious about native C++ development. This is demonstrated by the introduction of XmlLite, a high-performance, low-overhead XML reader and writer geared for applications written in native C++.

Enjoy!

Update: I’m getting a lot of email about XmlLite so here are the links you need in order to get going:

Download and install the latest Windows SDK, which provides the XmlLite header and lib files needed to compile and link. Although this is the SDK for Windows Vista, it also supports targeting Windows XP and Windows 2003.

If you don’t already have it, download and install XmlLite. This is only required for Windows XP x86 installations that haven’t already received it from Windows Update or some other means.


© 2007 Kenny Kerr

18 Comments

  • Excellent! Thanks for keeping the C++ articles coming. You got my 9. More please.

    John

  • John: thanks for the support - I appreciate it!

  • Kenny,

    Is this for Vista only? I'm looking all over for the .h and .lib so we can play with this stuff, and can't locate it anywhere :(

    Thanks

  • Phil: good question. XmlLite is also available for Windows XP and Windows 2003 but it was first introduced (if I remember correctly) in the Windows Vista SDK so you just need to get the latest version of the Windows SDK to get the header and lib files. The XmlLite.dll itself ships with Windows Vista but you need to make sure its installed on Windows XP and 2003. The latest service pack for Windows 2003 and as well as x64 editions of XP include XmlLite. For x86 editions of XP you can download it here. The next service pack will include it.

  • Hey Kenny,

    Thx for the quick reply - ok, I'll go find the latest Vista SDK (I'm still running WinXP for developement). I do have the DLL already (from a Windows Update).

    Just a thought - maybe you would post the .lib and .h on your site here for people running XP who don't want to go find/download/install the Vista SDK? :)

    Thanks,
    - Phil



  • Phil: Although the Windows SDK is freely available, I don’t think it’s permitted to redistribute any part of the SDK. Also the headers may have dependencies on updates to the Windows headers that it ships with so it’s best just to install the latest version of the Windows SDK. You can download it here.

  • Good point...

    I'm installing now - thanks for the help!

    (and good article in MSDN, btw!)

  • Kenny,

    I just stumbled upon your blog and was quite surprised and pleased to find that your examples are in good old-fashioned C++. I was further pleased to learn that many of your examples use ATL/WTL. In the new Microsoft world of .NET and such, I had thought that C++ was out of vogue. As a developer who principally uses C++ and ATL/WTL, I want to say thanks for your well-written, interesting articles. Keep it up.

  • Ok this xmllite seems good. I need a simple xml parser to read an xml file. Building my app requires the xmllite.h/.lib which is fine because I can get those from the SDK. But can I distribute the xmllite.dll runtime with my application release? (not using the install wizard of xmllite) It's not standard with WindowsXP which our customers use.

  • Larry: Unfortunately I don’t think there is a redistributable at the moment. Your customers can get it from Windows Update and I hear it also comes with IE7 so as long as the XP installations are up to date they should have it. I’d also like to see a redistributable though.

  • Deveoped a windows service using MSXML Parser and COM. This is a Multithreaded appilcation (procesing of xml files) and also uses xsl( applied to xml).This applicaiion runs as windows service.

    i am experiencing performence and memory leaks problem.
    Is it possible to replace MSXML with XmlLite.

    Thanks in advance.
    Sateesh

  • Sateesh: Simply replacing MSXML with XmlLite is unlikely to solve your problem. MSXML is heavily used by thousands of applications. It unlikely to be the source of your resource leaks. Concentrate on you application to see whether you are failing to release COM interface pointers, forgetting to free BSTR strings, etc.

    As for moving from MSXML to XmlLite, as I mentioned in the article, XmlLite only provides a subset of the functionality provided by MSXML. XmlLite also uses a different set of interfaces so you will likely have to rewrite portions of your application, but it’s certainly possible and XmlLite is certainly a lot faster.

  • I liked the article, especially when you do comparisons between the different ways to parse XML (lightweight vs heavy, managed versus native). But glaringly missing is the comparison of your library versus other lightweight alternatives (notably TinyXML). Is this something you could address?

  • Eddo: The article wasn’t primarily about which parser is best although I felt it instructive to position it next to its peers among the XML parsers offered by Microsoft. As I mentioned, there are things a DOM-style parser such as MSXML can do that XmlLite cannot directly offer at this point. As for TinyXML, I am not too familiar with the parser but it appears to be a DOM-style parser and thus not directly comparable to XmlLite which is a high-performance, forward-only parser.

  • Okay. I gave XmlLite a workout this weekend by writing a parser for some xml pages. The library performed quite well and it was very easy to use. I will now use this library for the rest of my project. But, I am wondering if Microsoft intends to release a Windows Mobile version of this for Windows Mobile devices? The application I'm working on will benefit from having a limited, but useful set of functionality that makes use of XmlLite. Any thought on where Microsft will go with this? I want to use the same code for desktop and Pocket PC devices.

  • Twain: The Windows Mobile team is not planning on including XmlLite at this point. I suspect they may add it in future if there is sufficient demand. I agree that would be an awesome alternative to what they offer today with MSXML and SAX.

  • Wonderful. Haven't downloaded or checked it out yet. But a quick question: Can this be used inside of dllmain? When developing a dll, most of the time, we want the dll to be totally initialized inside of dllmain, without the need of a special, "Init", "Load", "Start", etc function that someone else has to call. It looks like XmlLite loads the COM subsystem, which is verboten for DllMain(). I'm currently using "expat" to handle these cases. It is just as complicated as using SAX2, need to maintain a state stack, but doesn't load any additionally libraries, hence is clean for dllmain.

  • Unfortunately I cannot confirm whether or not it’s safe to use from DllMain. What I can comment on is your assertion about COM. XmlLite does *not* require the COM runtime/libraries to be loaded. In that sense XmlLite is probably your best bet as it has precious few dependencies. There may be some internal implementation details that prohibit its (safe) use from DllMain but I know of none.

    I must however add my usual disclaimer that you should avoid as much as possible doing anything “interesting” in DllMain due to the serialized way it is called by the runtime and the issues with the loader lock.

Comments have been disabled for this content.