Difference between revisions of "Overview"
(→Why use XeuMeuLeu) |
(→What is XeuMeuLeu) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 23: | Line 23: | ||
* output is formated for human readability | * output is formated for human readability | ||
* input can be validated against an XML schema definition ([http://www.w3.org/XML/Schema XSD]) | * input can be validated against an XML schema definition ([http://www.w3.org/XML/Schema XSD]) | ||
+ | * namespaces are supported | ||
* transformations can be applied using the extensible stylesheet language ([http://xmlfr.org/w3c/TR/xslt XSL]) | * transformations can be applied using the extensible stylesheet language ([http://xmlfr.org/w3c/TR/xslt XSL]) | ||
Line 50: | Line 51: | ||
<document> | <document> | ||
<element name="my element" /> | <element name="my element" /> | ||
− | <another-element> | + | <another-element>42</another-element> |
</document> | </document> | ||
Line 57: | Line 58: | ||
#include <xeumeuleu/xml.h> | #include <xeumeuleu/xml.h> | ||
− | std::string name | + | std::string name; |
+ | int content; | ||
xml::xifstream xis( "my_document.xml" ); | xml::xifstream xis( "my_document.xml" ); | ||
xis >> xml::start( "document" ) | xis >> xml::start( "document" ) | ||
Line 67: | Line 69: | ||
Writing the same file would be symmetrical : | Writing the same file would be symmetrical : | ||
− | #include <xeumeuleu/xml. | + | #include <xeumeuleu/xml.hpp> |
xml::xofstream xos( "my_document.xml" ); | xml::xofstream xos( "my_document.xml" ); | ||
Line 74: | Line 76: | ||
<< xml::attribute( "name", "my element" ) | << xml::attribute( "name", "my element" ) | ||
<< xml::end | << xml::end | ||
− | << xml::content( "another-element", | + | << xml::content( "another-element", 42 ); |
Applying a transformation based for instance on the stylesheet : | Applying a transformation based for instance on the stylesheet : | ||
Line 94: | Line 96: | ||
Using the code : | Using the code : | ||
− | #include <xeumeuleu/xsl. | + | #include <xeumeuleu/xsl.hpp> |
xsl::xftransform xft( "stylesheet.xsl", "output.html" ); | xsl::xftransform xft( "stylesheet.xsl", "output.html" ); | ||
Line 101: | Line 103: | ||
<< xml::attribute( "name", "my element" ) | << xml::attribute( "name", "my element" ) | ||
<< xml::end | << xml::end | ||
− | << xml::content( "another-element", | + | << xml::content( "another-element", 42 ) |
<< xml::end; | << xml::end; | ||
Line 111: | Line 113: | ||
<itemizedlist> | <itemizedlist> | ||
<listitem>Element : my element</listitem> | <listitem>Element : my element</listitem> | ||
− | <listitem>Another element : | + | <listitem>Another element : 42</listitem> |
</itemizedlist> | </itemizedlist> | ||
</body> | </body> |
Latest revision as of 08:26, 30 November 2010
This section introduces the library in a 3 mn overview.
Further information can be found in :
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 :
<document> <element name="my element" /> <another-element>42</another-element> </document>
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="/"> <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.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 :
<html> <body> <h2>Document</h2> <itemizedlist> <listitem>Element : my element</listitem> <listitem>Another element : 42</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.