are simply ignored.
What follows are the native GraphML attributes that are recognized:
- graph: edgedefault (takes values {"undirected","directed"}; determines whether the graph is directed or undirected)
- node: id (Can be any string value; only used to connect up edges)
- edge: source, target (take ids; both are used to created either a directed or undirected edge depending
on the type of graph)
These attributes are not stored as explicit UserDatum instances. All other attributes are read in and stored as
UserDatum String values with the corresponding graph object, i.e. graph, node, or edge.
A sample file looks like this:
<?xml version="1.0" encoding="iso-8859-1" ?>
<?meta name="GENERATOR" content="XML::Smart 1.3.1" ?>
<?meta name="GENERATOR" content="XML::Smart 1.3.1" ?>
<graph edgedefault="directed" year="1983">
<node id="1" name="V1" color="red"/>
<node id="2" name="V2" color="blue"/>
<node id="3" name="V3" color="green"/>
<edge source="1" target="2" day="Monday"/>
<edge source="1" target="3" day="Tuesday"/>
<edge source="2" target="3" day="Friday"/>
</graph>
Note: In this example, year, color, and day are user-defined attributes that get stored in the object's UserData
Assuming we have a Graph g created from the above XML file we can print out the days of
the week for each node as follows:
for (Iterator eIt = g.getEdges().iterator(); eIt.hasNext(); ) {
Edge v = (Edge) eIt.next();
System.out.println(e.getUserDatum("day");
}
- Author:
- Scott White, John Yesberg
- See Also:
- "http://graphml.graphdrawing.org/"
Constructor Summary |
GraphMLFile()
Default constructor which uses default GraphMLFileHandler to parse the graph |
GraphMLFile(GraphMLFileHandler handler)
Constructors which allows a subclass of GraphMLFileHandler to be used to parse the graph |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
directed
protected boolean directed
undirected
protected boolean undirected
GraphMLFile
public GraphMLFile()
- Default constructor which uses default GraphMLFileHandler to parse the graph
GraphMLFile
public GraphMLFile(GraphMLFileHandler handler)
- Constructors which allows a subclass of GraphMLFileHandler to be used to parse the graph
- Parameters:
handler
- the user-provided GraphML file handler
load
public Graph load(String filename)
- Loads a graph from a GraphML file.
- Specified by:
load
in interface GraphFile
- Parameters:
filename
- the fully specified file name
- Returns:
- the constructed graph
load
public Graph load(InputStream stream)
- Deprecated. generally, InputStreams are less robust than Readers
- Loads a graph from a GraphML input stream.
- Parameters:
stream
- the input stream which contains the GraphML data
- Returns:
- the constructed graph
load
public Graph load(Reader reader)
loadGraphCollection
public List loadGraphCollection(String dirName,
FilenameFilter filter)
- Loads in a list of graphs whose corresponding filenames pass the file filter and are located in the
specified directory
- Parameters:
dirName
- the directory containing the set of files that are to be screened through the file filterfilter
- the file filter
- Returns:
- a list of graphs
save
public void save(Graph g,
String filename)
- Description copied from interface:
GraphFile
- Save a graph to disk per the appropriate format
- Specified by:
save
in interface GraphFile
- Parameters:
g
- the location and name of the filefilename
- the graph
save
public void save(Graph g,
PrintStream out)
setGraphMLFileHandler
public void setGraphMLFileHandler(GraphMLFileHandler fileHandler)
- Allows the user to provide his/her own subclassed GraphML file handerl
- Parameters:
fileHandler
-