public class GraphMLFile extends java.lang.Object implements GraphFile
What follows are the native GraphML attributes that are recognized:
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"); }
Modifier and Type | Field and Description |
---|---|
protected boolean |
directed |
protected boolean |
undirected |
Constructor and Description |
---|
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
|
Modifier and Type | Method and Description |
---|---|
Graph |
load(java.io.InputStream stream)
Deprecated.
generally, InputStreams are less robust than Readers
|
Graph |
load(java.io.Reader reader) |
Graph |
load(java.lang.String filename)
Loads a graph from a GraphML file.
|
java.util.List |
loadGraphCollection(java.lang.String dirName,
java.io.FilenameFilter filter)
Loads in a list of graphs whose corresponding filenames pass the file filter and are located in the
specified directory
|
void |
save(Graph g,
java.io.PrintStream out) |
void |
save(Graph g,
java.lang.String filename)
Save a graph to disk per the appropriate format
|
void |
setGraphMLFileHandler(GraphMLFileHandler fileHandler)
Allows the user to provide his/her own subclassed GraphML file handerl
|
public GraphMLFile()
public GraphMLFile(GraphMLFileHandler handler)
handler
- the user-provided GraphML file handlerpublic Graph load(java.lang.String filename)
public Graph load(java.io.InputStream stream)
stream
- the input stream which contains the GraphML datapublic Graph load(java.io.Reader reader)
public java.util.List loadGraphCollection(java.lang.String dirName, java.io.FilenameFilter filter)
dirName
- the directory containing the set of files that are to be screened through the file filterfilter
- the file filterpublic void save(Graph g, java.lang.String filename)
GraphFile
public void save(Graph g, java.io.PrintStream out)
public void setGraphMLFileHandler(GraphMLFileHandler fileHandler)
fileHandler
-