Boost logo

Boost :

Subject: Re: [boost] [ANN] libstudxml - modern XML API for C++
From: Stefan Seefeld (stefan_at_[hidden])
Date: 2014-05-21 11:15:31


On 2014-05-21 10:53, Boris Kolpackov wrote:
> Hi,
>
> libstudxml is an XML library for modern, standard C++. It has an API
> that I believe should have already been in Boost or even in the C++
> standard library.

Hi Boris,

very interesting ! There is an XML library in the boost sandbox (now
https://github.com/stefanseefeld/boost.xml), which has been around for
many years.

> The API was first presented at the C++Now 2014 conference. Based on
> the positive feedback and encouragement I received during the talk,
> I've decided to make the implementation generally available.
>
> As an example, we can parse this XML:
>
> <person id="123">
> <name>John Doe</name>
> <age>23</age>
> <gender>male</gender>
> </person>
>
> With the following C++ code, which performs all the validation
> necessary for this XML vocabulary:
>
> enum class gender {...};
>
> ifstream ifs (argv[1]);
> parser p (ifs, argv[1]);
>
> p.next_expect (parser::start_element, "person", content::complex);
>
> long id = p.attribute<long> ("id");
>
> string n = p.element ("name");
> short a = p.element<short> ("age");
> gender g = p.element<gender> ("gender");
>
> p.next_expect (parser::end_element); // person
>
> The API has the following interesting features:
>
> * Streaming pull parser and streaming serializer
> * Two-level API: minimum overhead low-level & more convenient high-level
> * Content model-aware (empty, simple, complex, mixed)
> * Whitespace processing based on content model
> * Validation based on content model
> * Validation of missing/extra attributes
> * Validation of unexpected events (elements, etc)
> * Data extraction to value types
> * Attribute map with extended lifetime (high-level API)
>
> libstudxml is compact, external dependency-free, and reasonably
> efficient. The XML parser is a conforming, non-validating XML 1.0
> implementation that is based on tested and proven code. The library
> is released under the MIT license.

Does it support a DOM-like API, i.e. an in-memory representation of the
document ?

I have always strongly argued against the idea that an "XML API" was
only about parsing XML data, as there are many useful features that
involve manipulation of XML data (including transformations between
documents, xpath-based search, etc.).
I have also argued that re-implementing all that functionality from
scratch is foolish with so many existing implementations, so any
boost.xml project should focus on wrapping such implementations, rather
than reinventing them. In fact, I believe such an API should be robust
enough to be able to wrap different backends, rather than depending on a
particular implementation choice.
As it happens, we have a project working on those features as part of
this year's Google Summer of Code program. It would be great if we could
collaborate towards a shared goal to define a feature-rich and robust
Boost.XML library.

> More information, documentation, and source code are available from:
>
> http://www.codesynthesis.com/projects/libstudxml/
>
> Or, you can jump directly to the API description with examples:
>
> http://www.codesynthesis.com/projects/libstudxml/doc/intro.xhtml#2

Thanks for sharing !

        Stefan

-- 
      ...ich hab' noch einen Koffer in Berlin...

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk