Main Page

From wiki
Revision as of 13:56, 1 June 2009 by Mat007 (Talk | contribs)

Jump to: navigation, search

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)
  • 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 features
  • the open-source license guarantees code availability and usability even for commercial applications
  • the unit tests coverage greatly helps reducing the risk of bugs within the library

What XeuMeuLeu looks like

Given the following XML document :

<document>
  <element name="my element" />
  <another-element>my content</another-element>
</document>

The code to read it would simply be :

#include <xeumeuleu/xml.h>
std::string name, 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.h>
xml::xofstream xos( "my_document.xml" );
xos << xml::start( "document" )
      << xml::start( "element" )
        << xml::attribute( "name", "my element" )
      << xml::end
      << xml::content( "another-element", "my content" );

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="/">
    <html>
    <body>
      <h2>Document</h2>
      <itemizedlist>
        <listitem>Element : <xsl:value-of select="document/element/@name"/></listitem>
        <listitem>Another element : <xsl:value-of select="document/another-element"/></listitem>
      </itemizedlist>
    </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

Using the code :

#include <xeumeuleu/xsl.h>
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", "my content" )
    << xml::end;

Would output the HTML file :

<html>
  <body>
    <h2>Document</h2>
    <itemizedlist>
      <listitem>Element : my element</listitem>
      <listitem>Another element : my content</listitem>
    </itemizedlist>
  </body>
</html>

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.