Hi Martin,
Martin Halle <ma**********@gmx.netwrites:
I'm using XML in a project. This is a very simple and small file that
follows an even simpler XSD schema. I've found a lightweight library
(TinyXML) to read and access the contents of the XML file in C++.
Now I'm looking for something similar to validate a given XML file
agains a XSD schema.
General-purpose XML Schema validators are usually neither simple nor
lightweight ;-). You might be interested in the so called "perfect
parser" approach where the validation code is generated by a tool
specifically for your schema. If your schema is fairly simple then
the resulting code will be small as well. A well-implemented perfect
parser will also perform several times faster than general-purpose
validators.
One such tool is CodeSynthesis XSD[1] and its C++/Parser mapping[2]
(full disclosure: I am working on this project). It is an open-source
(GPL + proprietary license), cross-platform XML data binding compiler
for C++.
This library should:
- be lightweight (!)
Executable size for a small schema (our benchmark) is around 250K.
- thus not depend on xerces, MSXML and similar
It uses Expat as the underlying XML parser. Expat is fairly small
and is the fastest among Xerces-C++, MSXML, and libxml2.
- cross-platform (g++) compatible
Check. See the list of supported platforms and compilers[3].
- can use STL (this would be a nice-to-have)
Uses standard C++ and STL.
[1]
http://codesynthesis.com/products/xsd/
[2]
http://codesynthesis.com/products/xsd/c++/parser/
[3]
http://codesynthesis.com/products/xsd/platforms.xhtml
hth,
-boris