This library is no longer maintained and doesn't support the latest version of the format specifications. We recommend to use other librairies, for which we've provided links. If you're interested in becoming a contributor and update the code, feel free to reach out at contact@gexf.net

What is it?

Easy to use the Graph Exchange XML Format in your programs!

Libgexf is the official C++ toolkit library for the GEXF file format. It is free software available under the MIT License. Though the library is written in C++ a variety of language bindings make it available in other environments.

Libgexf currently only works on Linux systems (tested on Ubuntu 8.10 and 9.04), but the portability will be increased on demand. Python, Perl and Java binding facilities are also provided.

How to use it?

Using the library in your C++ programs is very simple:

  1. add -I/usr/include/libgexf -I/usr/include/libxml2 to the g++ compiler options
  2. add -lgexf -lxml2 to the g++ linker options
  3. insert #include <libgexf.h> in your C++ program. Namespace: libgexf

That's all, folks! See related README files for each language binding.

Features

  • static graph
  • basic topology (no hierarchical graphs or hypergraphs for the moment)
  • full data attributes
  • read/write GEXF 1.0 (legacy Gephi 0.6) and 1.1 (Gephi 0.7+)
  • data integrity and type checking
  • RelaxNG and XSD validator

Example

This is how to create a GEXF file:

#include <stdlib.h>

// if libgexf is installed
#include <libgexf/libgexf.h>

void create() {

    libgexf::GEXF *gexf = new libgexf::GEXF();

    libgexf::DirectedGraph& graph = gexf->getDirectedGraph();

    // nodes
    graph.addNode("0");
    graph.addNode("1");

    // edges
    graph.addEdge("0", "0", "1");

    // node labels
    libgexf::Data& data = gexf->getData();
    data.setLabel("0", "Hello");
    data.setLabel("1", "world");

    // attributes
    data.addNodeAttributeColumn("0", "foo", libgexf::BOOLEAN);
    data.setNodeAttributeDefault("0", "false");
    data.setNodeValue("1", "0", "true");

    // meta data
    libgexf::MetaData& meta = gexf->getMetaData();
    meta.setCreator("The Hitchhiker's Guide to the Galaxy");
    meta.setDescription("The answer is 42.");

    // write gexf file
    libgexf::FileWriter *writer = new libgexf::FileWriter();
    writer->init("life.gexf", gexf);
    writer->write();
}

The result will be:

<?xml version="1.0" encoding="UTF-8"?>
<gexf xmlns="http://www.gexf.net/1.1" version="1.1">
    <meta>
        <creator>The Hitchhiker's Guide to the Galaxy<creator>
        <description>The answer is 42.<description>
    </meta>
    <graph mode="static" defaultedgetype="undirected">
        <attributes class="node">
            <attribute id="0" title="foo" type="boolean">
                <default>false</default>
            </attribute>
        </attributes>
        <nodes>
            <node id="0" label="Hello"/>
            <node id="1" label="world"/>
                <attvalues>
                    <attvalue for="0" value="true">
                </attvalues>
            </node>
        </nodes>
        <edges>
            <edge id="0" source="0" target="1"/>
        </edges>
    </graph>
</gexf>

Release policy

The development is divided into 2 series: stable and unstable. The stable serie represents an interface which should not change until further additions, and is well tested. The unstable serie is the cutting-edge development version packaged for testing. Interfaces may change.

Stable serie has a pair second revision number, i.e. 1.2.x
Unstable serie has an odd second revision number, i.e. 1.1.x

Get started!

Download the latest release and try the examples now!