From wiki
Jump to: navigation, search

This section introduces the library in a 3 mn overview.

Further information can be found in :

  • the manual which describes all features
  • the patterns which gather more advanced use cases

What is XeuMeuLeu

XeuMeuLeu is an open-source cross-platform C++ stream oriented library on top of Apache Xerces for manipulating XML and Apache Xalan for applying XSL transformations.

It aims at hiding complexity by providing an easy means to read, write and transform XML.

The following features are available :

  • source can be a string, a file, a URL, any std::istream or an internal buffer
  • destination can be a string, a file or an internal buffer
  • encoding can be any of the encodings supported by Apache Xerces
  • output is formated for human readability
  • input can be validated against an XML schema definition (XSD)
  • namespaces are supported
  • transformations can be applied using the extensible stylesheet language (XSL)

What XeuMeuLeu is not

XeuMeuLeu is not an XML parser as it relies on Apache Xerces for this.

XeuMeuLeu is not an XSLT processor as it relies on Apache Xalan for this.

XeuMeuLeu does not turn Apache Xerces into a pull-parser, XML documents are parsed in memory when a stream is created or flushed to the stream when the document is complete.

XeuMeuLeu is not a data-binding framework, it does not automatically (un)serialize objects.

Why use XeuMeuLeu

Because of the following benefits :

  • the high-level stream oriented design allows to quickly write easy and simple code
  • the underlying use of Apache Xerces as well as Apache Xalan ensures a wide range of stable features
  • the open-source license guarantees code availability and usability even for commercial applications
  • the extensive unit test suite greatly minimizes the risk of bugs or regressions within the library

What XeuMeuLeu looks like

Given the following XML document :

  <element name="my element" />

The code to read it would be :

#include <xeumeuleu/xml.h>

std::string name;
int content;
xml::xifstream xis( "my_document.xml" );
xis >> xml::start( "document" )
      >> xml::start( "element" )
        >> xml::attribute( "name", name )
      >> xml::end
      >> xml::content( "another-element", content );

Writing the same file would be symmetrical :

#include <xeumeuleu/xml.hpp>

xml::xofstream xos( "my_document.xml" );
xos << xml::start( "document" )
      << xml::start( "element" )
        << xml::attribute( "name", "my element" )
      << xml::end
      << xml::content( "another-element", 42 );

Applying a transformation based for instance on the stylesheet :

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
        <listitem>Element : <xsl:value-of select="document/element/@name"/></listitem>
        <listitem>Another element : <xsl:value-of select="document/another-element"/></listitem>

Using the code :

#include <xeumeuleu/xsl.hpp>

xsl::xftransform xft( "stylesheet.xsl", "output.html" );
xft << xml::start( "document" )
      << xml::start( "element" )
        << xml::attribute( "name", "my element" )
      << xml::end
      << xml::content( "another-element", 42 )
    << xml::end;

Would output the HTML file :

      <listitem>Element : my element</listitem>
      <listitem>Another element : 42</listitem>

Of course those are a few examples only intended to demonstrate the feel of the library.
The user manual provides an extensive description of all features.