GraphML Serialization

GraphML is a comprehensive and easy-to-use file format for graphs. QuickGraph supports loading and saving directed graphs to this format. The GraphML serialization APIs are exposed through the GraphMLExtensions extension methods (in QuickGraph.Serialization.

The serialization code uses dynamic code generation to provide high performance in reading and writing custom properties.
Serializing graphs
To serialize a graph, simply call the SerializeToGraphML extension methods with an XmlWriter instance.
var g = new AdjacencyGraph<int, Edge<int>>();
using(var xwriter = XmlWriter.Create(...))

Deserializing graphs

To deserialize a graph, create the graph instance and call the DeserializeFromGraphML:
var g = new AdjacencyGraph<int, Edge<int>>();
using(var xreader = XmlReader.Create(...))
         id => int.Parse(id), 
         (source, target, id) => new Edge<int>(source, target)

Serializing Custom Fields
The serializer supports the XmlAttributeAttribute attribute on public properties of the vertex, edge and graph types. These properties will be declared and serialized in the GraphML stream. The supported property types are bool, int, long, float, double and string.

class IntEdge : Edge<int> {
   public string Name {get;set;}

Default values can also be specified for the properties by using the DefaultValueAttribute attribute:
   public string Name {get;set;}

Last edited Jan 22, 2009 at 4:00 PM by pelikhan, version 9


No comments yet.