C# Class Smrf.NodeXL.Adapters.GraphMLGraphAdapter

Converts a graph to and from a GraphML file.
A good introduction to GraphML can be found in the GraphML Primer:

http://graphml.graphdrawing.org/primer/graphml-primer.html

Here is a sample GraphML file that can be converted. It represents a graph with three vertices and two edges.

<?xml version="1.0" encoding="UTF-8"?> <graphml xmlns="http://graphml.graphdrawing.org/xmlns"> <key id="EdgeWidth" for="edge" attr.name="Width" attr.type="double"> <default>1.5</default> </key> <key id="VertexColor" for="node" attr.name="Color" attr.type="string" /> <key id="LatestPostDate" for="node" attr.name="Latest Post Date" attr.type="string" /> <graph edgedefault="undirected"> <node id="V1"> <data key="VertexColor">red</data> </node> <node id="V2"> <data key="VertexColor">orange</data> </node> <node id="V3"> <data key="VertexColor">blue</data> </node> <edge source="V1" target="V2"> <data key="LatestPostDate">2009/07/05</data> </edge> <edge source="V3" target="V2"> <data key="EdgeWidth">2.5</data> <data key="LatestPostDate">2009/07/12</data> </edge> </graph> </graphml>

Edge and vertex attributes, which GraphML calls "GraphML-attributes," are supported by this class. When loading a graph, if an edge or vertex has a GraphML-attribute, it gets added to the metadata of the or IVertex. The metadata key is the GraphML-attribute's attr.name value and the metadata value is the GraphML-attribute's value. When saving a graph, every metadata value on every edge and vertex gets converted to a GraphML-attribute in the saved GraphML.

To make it possible for the caller to determine which metadata keys were added to the graph's edges and vertices, the LoadXX methods add and keys to the returned graph. The key values are of type String[].

If there is an optional "description" attribute on the "graph" XML node, the LoadXX methods copy its value to a key on the returned graph.

If there is an optional "suggestedFileNameNoExtension" attribute on the "graph" XML node, the LoadXX methods copy its value to a key on the returned graph.

When saving a graph, the caller must add and keys to the graph before calling IGraphAdapter.SaveGraph(IGraph, Stream).

Inheritance: GraphAdapterBase, IGraphAdapter
Mostrar archivo Open project: 2014-sed-team3/term-project Class Usage Examples

Public Methods

Method Description
AssertValid ( ) : void
GraphMLGraphAdapter ( ) : System

Initializes a new instance of the GraphMLGraphAdapter class.

Protected Methods

Method Description
AppendGraphMLAttributeValues ( IMetadataProvider oEdgeOrVertex, GraphMLXmlDocument oGraphMLXmlDocument, XmlNode oEdgeOrVertexXmlNode, String asAttributeNames, String AttributeIDPrefix ) : void
GetGraphDirectedness ( XmlNode oGraphXmlNode ) : GraphDirectedness
GetSupportedDirectedness ( System.Boolean &supportsDirected, System.Boolean &supportsUndirected, System.Boolean &supportsMixed ) : void
LoadGraphCore ( Stream stream ) : IGraph
ParseEdges ( IGraph oGraph, XmlNode oGraphXmlNode, XmlNamespaceManager oXmlNamespaceManager, IVertex>.Dictionary oVertexDictionary, GraphMLAttribute>.Dictionary oGraphMLAttributeDictionary ) : void
ParseGraphAttribute ( IGraph oGraph, XmlNode oGraphXmlNode, String sXmlAttributeName, String sKey ) : void
ParseGraphMLAttributeDefinitions ( XmlNode oGraphMLXmlNode, XmlNamespaceManager oXmlNamespaceManager ) : GraphMLAttribute>.Dictionary
ParseGraphMLAttributeValues ( XmlNode oNodeOrEdgeXmlNode, XmlNamespaceManager oXmlNamespaceManager, IMetadataProvider oEdgeOrVertex, System.Boolean bIsVertex, GraphMLAttribute>.Dictionary oGraphMLAttributeDictionary ) : void
ParseVertices ( IGraph oGraph, XmlNode oGraphXmlNode, XmlNamespaceManager oXmlNamespaceManager, GraphMLAttribute>.Dictionary oGraphMLAttributeDictionary ) : IVertex>.Dictionary
SaveGraphCore ( IGraph graph, Stream stream ) : void
SaveGraphMLAttributeNames ( IGraph oGraph, GraphMLAttribute>.Dictionary oGraphMLAttributeDictionary ) : void
TryGraphMLNodeIDToVertex ( XmlNode oEdgeXmlNode, String sSourceOrTarget, IVertex>.Dictionary oVertexDictionary, IVertex &oVertex ) : System.Boolean

Method Details

AppendGraphMLAttributeValues() protected method

protected AppendGraphMLAttributeValues ( IMetadataProvider oEdgeOrVertex, GraphMLXmlDocument oGraphMLXmlDocument, XmlNode oEdgeOrVertexXmlNode, String asAttributeNames, String AttributeIDPrefix ) : void
oEdgeOrVertex IMetadataProvider
oGraphMLXmlDocument Smrf.XmlLib.GraphMLXmlDocument
oEdgeOrVertexXmlNode System.Xml.XmlNode
asAttributeNames String
AttributeIDPrefix String
return void

AssertValid() public method

public AssertValid ( ) : void
return void

GetGraphDirectedness() protected method

protected GetGraphDirectedness ( XmlNode oGraphXmlNode ) : GraphDirectedness
oGraphXmlNode System.Xml.XmlNode
return GraphDirectedness

GetSupportedDirectedness() protected method

protected GetSupportedDirectedness ( System.Boolean &supportsDirected, System.Boolean &supportsUndirected, System.Boolean &supportsMixed ) : void
supportsDirected System.Boolean
supportsUndirected System.Boolean
supportsMixed System.Boolean
return void

GraphMLGraphAdapter() public method

Initializes a new instance of the GraphMLGraphAdapter class.
public GraphMLGraphAdapter ( ) : System
return System

LoadGraphCore() protected method

protected LoadGraphCore ( Stream stream ) : IGraph
stream Stream
return IGraph

ParseEdges() protected method

protected ParseEdges ( IGraph oGraph, XmlNode oGraphXmlNode, XmlNamespaceManager oXmlNamespaceManager, IVertex>.Dictionary oVertexDictionary, GraphMLAttribute>.Dictionary oGraphMLAttributeDictionary ) : void
oGraph IGraph
oGraphXmlNode System.Xml.XmlNode
oXmlNamespaceManager System.Xml.XmlNamespaceManager
oVertexDictionary IVertex>.Dictionary
oGraphMLAttributeDictionary GraphMLAttribute>.Dictionary
return void

ParseGraphAttribute() protected method

protected ParseGraphAttribute ( IGraph oGraph, XmlNode oGraphXmlNode, String sXmlAttributeName, String sKey ) : void
oGraph IGraph
oGraphXmlNode System.Xml.XmlNode
sXmlAttributeName String
sKey String
return void

ParseGraphMLAttributeDefinitions() protected method

protected ParseGraphMLAttributeDefinitions ( XmlNode oGraphMLXmlNode, XmlNamespaceManager oXmlNamespaceManager ) : GraphMLAttribute>.Dictionary
oGraphMLXmlNode System.Xml.XmlNode
oXmlNamespaceManager System.Xml.XmlNamespaceManager
return GraphMLAttribute>.Dictionary

ParseGraphMLAttributeValues() protected method

protected ParseGraphMLAttributeValues ( XmlNode oNodeOrEdgeXmlNode, XmlNamespaceManager oXmlNamespaceManager, IMetadataProvider oEdgeOrVertex, System.Boolean bIsVertex, GraphMLAttribute>.Dictionary oGraphMLAttributeDictionary ) : void
oNodeOrEdgeXmlNode System.Xml.XmlNode
oXmlNamespaceManager System.Xml.XmlNamespaceManager
oEdgeOrVertex IMetadataProvider
bIsVertex System.Boolean
oGraphMLAttributeDictionary GraphMLAttribute>.Dictionary
return void

ParseVertices() protected method

protected ParseVertices ( IGraph oGraph, XmlNode oGraphXmlNode, XmlNamespaceManager oXmlNamespaceManager, GraphMLAttribute>.Dictionary oGraphMLAttributeDictionary ) : IVertex>.Dictionary
oGraph IGraph
oGraphXmlNode System.Xml.XmlNode
oXmlNamespaceManager System.Xml.XmlNamespaceManager
oGraphMLAttributeDictionary GraphMLAttribute>.Dictionary
return IVertex>.Dictionary

SaveGraphCore() protected method

protected SaveGraphCore ( IGraph graph, Stream stream ) : void
graph IGraph
stream Stream
return void

SaveGraphMLAttributeNames() protected method

protected SaveGraphMLAttributeNames ( IGraph oGraph, GraphMLAttribute>.Dictionary oGraphMLAttributeDictionary ) : void
oGraph IGraph
oGraphMLAttributeDictionary GraphMLAttribute>.Dictionary
return void

TryGraphMLNodeIDToVertex() protected method

protected TryGraphMLNodeIDToVertex ( XmlNode oEdgeXmlNode, String sSourceOrTarget, IVertex>.Dictionary oVertexDictionary, IVertex &oVertex ) : System.Boolean
oEdgeXmlNode System.Xml.XmlNode
sSourceOrTarget String
oVertexDictionary IVertex>.Dictionary
oVertex IVertex
return System.Boolean