You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Andrey Vernigora edited this page Feb 2, 2019
·
4 revisions
Xml Serialization
QuickGraph supports loading and saving graphs to and from Xml. The implementation builds on top of XmlReader and XmlWriter and is located in the SerializationExtensions class from the QuickGraph.Serialization namespace.
Serializing graphs
To serialize a graph, call the SerializeToXml extension methods with an XmlWriter instance and delegates that can map vertices and edges to an identifier string. The serialization method also supports custom delegate to write additional information per vertex, edge
classMyVertex{publicintID{get;set;}}classMyEdge:IEdge<MyVertex>{stringName{get;set;}stringTag{get;set;}}varg=newAdjacencyGraph<MyVertex,MyEdge>();
...using(varxwriter= XmlWriter.Create(...))g.SerializeToXml(xwriter,
v =>v.ID,// let's use ID as the vertex IDAlgorithmExtensions.GetEdgeIdentity(graph),// let QuickGraph give an id to edges"graph","myvertex","myedge",""// names of the graph, vertex, node xml tags and the namespace uri);
Deserializing graphs
To deserialize a graph, create the graph instance and call the DeserializeFromXml.
Serializing Custom Fields
The serializer supports the delegates to write additional information of the vertex, edge and graph types.