## 6.4. Export to GraphML

This section describes procedures that can be used to export data in GraphML format.

The export GraphML procedures export data into a format that’s used by other tools like Gephi and CytoScape to read graph data.

All `Point` or `Temporal` data types are exported formatted as a String

e.g:

`Point 3d` | {"crs":"wgs-84-3d","latitude":56.7,"longitude":12.78,"height":100.0}
`Point 2d` | {"crs":"wgs-84-3d","latitude":56.7,"longitude":12.78,"height":null}
`Date` | 2018-10-10
`LocalDateTime` | 2018-10-10T00:00

This section includes:

- Available Procedures
- Configuration parameters
- Exporting to a file
- Exporting a stream

- Examples

  - Export whole database
  - Export specified nodes and relationships
  - Export virtual graph
  - Export results of Cypher query

### 6.4.1. Available Procedures

The table below describes the available procedures:

type | qualified name | signature | description
--- | --- | --- | ---

procedure

`apoc.export.graphml.all`

`apoc.export.graphml.all(file :: STRING?, config :: MAP?) :: (file :: STRING?, source :: STRING?, format :: STRING?, nodes :: INTEGER?, relationships :: INTEGER?, properties :: INTEGER?, time :: INTEGER?, rows :: INTEGER?, batchSize :: INTEGER?, batches :: INTEGER?, done :: BOOLEAN?, data :: STRING?)`

apoc.export.graphml.all(file,config) - exports whole database as graphml to the provided file

procedure

`apoc.export.graphml.data`

`apoc.export.graphml.data(nodes :: LIST? OF NODE?, rels :: LIST? OF RELATIONSHIP?, file :: STRING?, config :: MAP?) :: (file :: STRING?, source :: STRING?, format :: STRING?, nodes :: INTEGER?, relationships :: INTEGER?, properties :: INTEGER?, time :: INTEGER?, rows :: INTEGER?, batchSize :: INTEGER?, batches :: INTEGER?, done :: BOOLEAN?, data :: STRING?)`

apoc.export.graphml.data(nodes,rels,file,config) - exports given nodes and relationships as graphml to the provided file

procedure

`apoc.export.graphml.graph`

`apoc.export.graphml.graph(graph :: MAP?, file :: STRING?, config :: MAP?) :: (file :: STRING?, source :: STRING?, format :: STRING?, nodes :: INTEGER?, relationships :: INTEGER?, properties :: INTEGER?, time :: INTEGER?, rows :: INTEGER?, batchSize :: INTEGER?, batches :: INTEGER?, done :: BOOLEAN?, data :: STRING?)`

apoc.export.graphml.graph(graph,file,config) - exports given graph object as graphml to the provided file

procedure

`apoc.export.graphml.query`

`apoc.export.graphml.query(query :: STRING?, file :: STRING?, config :: MAP?) :: (file :: STRING?, source :: STRING?, format :: STRING?, nodes :: INTEGER?, relationships :: INTEGER?, properties :: INTEGER?, time :: INTEGER?, rows :: INTEGER?, batchSize :: INTEGER?, batches :: INTEGER?, done :: BOOLEAN?, data :: STRING?)`

apoc.export.graphml.query(query,file,config) - exports nodes and relationships from the cypher statement as graphml to the provided file

The labels exported are ordered alphabetically. The output of `labels()` function is not sorted, use it in combination with `apoc.coll.sort()`.

### 6.4.2. Configuration parameters

The procedures support the following config parameters:

Table 6.41. configuration options
param | default | description
--- | --- | ---
format | gephi | In export to Graphml script define the export format. Possible value is: "gephi"
caption |  | It’s an array of string (i.e. ['name','title']) that define an ordered set of properties eligible as value for the `Label` value, if no match is found the there is a fallback to the node label, if the node label is missing the then the ID is used
useTypes | false | Write the attribute type information to the graphml output
batchSize | 20000 | define the batch size
delim | "," | define the delimiter character (export csv)
arrayDelim | ";" | define the delimiter character for arrays (used in the bulk import)
useTypes | false | add type on file header (export csv and graphml export)
storeNodeIds | false | set nodes' ids (import/export graphml)
readLabels | false | read nodes' labels (import/export graphml)
defaultRelationshipType | "RELATED" | set relationship type (import/export graphml)
separateFiles | false | export results in separated file by type (nodes, relationships..)
stream | false | stream the xml directly to the client into the `data` field

### 6.4.3. Exporting to a file

By default exporting to the file system is disabled. We can enable it by setting the following property in `apoc.conf`:

apoc.conf.

    apoc.export.file.enabled=true

If we try to use any of the export procedures without having first set this property, we’ll get the following error message:

Failed to invoke procedure: Caused by: java.lang.RuntimeException: Export to files not enabled, please set apoc.export.file.enabled=true in your neo4j.conf

Export files are written to the `import` directory, which is defined by the `dbms.directories.import` property. This means that any file path that we provide is relative to this directory. If we try to write to an absolute path, such as `/tmp/filename`, we’ll get an error message similar to the following one:

Failed to invoke procedure: Caused by: java.io.FileNotFoundException: /path/to/neo4j/import/tmp/fileName (No such file or directory)

We can enable writing to anywhere on the file system by setting the following property in `apoc.conf`:

apoc.conf.

    apoc.import.file.use_neo4j_config=false

| Neo4j will now be able to write anywhere on the file system, so be sure that this is your intention before setting this property.

### 6.4.4. Exporting a stream

If we don’t want to export to a file, we can stream results back in the `data` column instead by passing a file name of `null` and providing the `stream:true` config.

### 6.4.5. Examples

This section includes examples showing how to use the export to Cypher procedures. These examples are based on a movies dataset, which can be imported by running the following Cypher query:

    CREATE (TheMatrix:Movie {title:'The Matrix', released:1999, tagline:'Welcome to the Real World'})
    CREATE (Keanu:Person {name:'Keanu Reeves', born:1964})
    CREATE (Carrie:Person {name:'Carrie-Anne Moss', born:1967})
    CREATE (Laurence:Person {name:'Laurence Fishburne', born:1961})
    CREATE (Hugo:Person {name:'Hugo Weaving', born:1960})
    CREATE (LillyW:Person {name:'Lilly Wachowski', born:1967})
    CREATE (LanaW:Person {name:'Lana Wachowski', born:1965})
    CREATE (JoelS:Person {name:'Joel Silver', born:1952})
    CREATE
    (Keanu)-[:ACTED_IN {roles:['Neo']}]->(TheMatrix),
    (Carrie)-[:ACTED_IN {roles:['Trinity']}]->(TheMatrix),
    (Laurence)-[:ACTED_IN {roles:['Morpheus']}]->(TheMatrix),
    (Hugo)-[:ACTED_IN {roles:['Agent Smith']}]->(TheMatrix),
    (LillyW)-[:DIRECTED]->(TheMatrix),
    (LanaW)-[:DIRECTED]->(TheMatrix),
    (JoelS)-[:PRODUCED]->(TheMatrix);

The Neo4j Browser visualization below shows the imported graph:

Figure 6.4. Movies Graph Visualization

#### 6.4.5.1. Export whole database to GraphML

The `apoc.export.graphml.all` procedure exports the whole database to a GraphML file or as a stream.

The following query exports the whole database to the file `movies.graphml`.

    CALL apoc.export.graphml.all("movies.graphml", {})

Table 6.42. Results
file | source | format | nodes | relationships | properties | time | rows | batchSize | batches | done | data
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
"movies.graphml" | "database: nodes(8), rels(7)" | "graphml" | 8 | 7 | 21 | 4 | 15 | -1 | 0 | TRUE | NULL

movies.graphml.

    <?xml version="1.0" encoding="UTF-8"?>
    <graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
    <key id="born" for="node" attr.name="born"/>
    <key id="name" for="node" attr.name="name"/>
    <key id="tagline" for="node" attr.name="tagline"/>
    <key id="label" for="node" attr.name="label"/>
    <key id="title" for="node" attr.name="title"/>
    <key id="released" for="node" attr.name="released"/>
    <key id="roles" for="edge" attr.name="roles"/>
    <key id="label" for="edge" attr.name="label"/>
    <graph id="G" edgedefault="directed">
    <node id="n188" labels=":Movie"><data key="labels">:Movie</data><data key="title">The Matrix</data><data key="tagline">Welcome to the Real World</data><data key="released">1999</data></node>
    <node id="n189" labels=":Person"><data key="labels">:Person</data><data key="born">1964</data><data key="name">Keanu Reeves</data></node>
    <node id="n190" labels=":Person"><data key="labels">:Person</data><data key="born">1967</data><data key="name">Carrie-Anne Moss</data></node>
    <node id="n191" labels=":Person"><data key="labels">:Person</data><data key="born">1961</data><data key="name">Laurence Fishburne</data></node>
    <node id="n192" labels=":Person"><data key="labels">:Person</data><data key="born">1960</data><data key="name">Hugo Weaving</data></node>
    <node id="n193" labels=":Person"><data key="labels">:Person</data><data key="born">1967</data><data key="name">Lilly Wachowski</data></node>
    <node id="n194" labels=":Person"><data key="labels">:Person</data><data key="born">1965</data><data key="name">Lana Wachowski</data></node>
    <node id="n195" labels=":Person"><data key="labels">:Person</data><data key="born">1952</data><data key="name">Joel Silver</data></node>
    <edge id="e267" source="n189" target="n188" label="ACTED_IN"><data key="label">ACTED_IN</data><data key="roles">["Neo"]</data></edge>
    <edge id="e268" source="n190" target="n188" label="ACTED_IN"><data key="label">ACTED_IN</data><data key="roles">["Trinity"]</data></edge>
    <edge id="e269" source="n191" target="n188" label="ACTED_IN"><data key="label">ACTED_IN</data><data key="roles">["Morpheus"]</data></edge>
    <edge id="e270" source="n192" target="n188" label="ACTED_IN"><data key="label">ACTED_IN</data><data key="roles">["Agent Smith"]</data></edge>
    <edge id="e271" source="n193" target="n188" label="DIRECTED"><data key="label">DIRECTED</data></edge>
    <edge id="e272" source="n194" target="n188" label="DIRECTED"><data key="label">DIRECTED</data></edge>
    <edge id="e273" source="n195" target="n188" label="PRODUCED"><data key="label">PRODUCED</data></edge>
    </graph>
    </graphml>

The following query returns a stream of the whole database in the `data` column.

    CALL apoc.export.graphml.all(null, {stream:true})
    YIELD file, nodes, relationships, properties, data
    RETURN file, nodes, relationships, properties, data;

Table 6.43. Results
file | nodes | relationships | properties | data
--- | --- | --- | --- | ---

NULL

8

7

21

    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
     <graphml xmlns="\"http://graphml.graphdrawing.org/xmlns\""
              xmlns:xsi="\"http://www.w3.org/2001/XMLSchema-instance\""
              xsi:schemaLocation="\"http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\"">
       <key id="\"born\"" for="\"node\"" attr.name="\"born\""/>
       <key id="\"name\"" for="\"node\"" attr.name="\"name\""/>
       <key id="\"tagline\"" for="\"node\"" attr.name="\"tagline\""/>
       <key id="\"label\"" for="\"node\"" attr.name="\"label\""/>
       <key id="\"title\"" for="\"node\"" attr.name="\"title\""/>
       <key id="\"released\"" for="\"node\"" attr.name="\"released\""/>
       <key id="\"roles\"" for="\"edge\"" attr.name="\"roles\""/>
       <key id="\"label\"" for="\"edge\"" attr.name="\"label\""/>
       <graph id="\"G\"" edgedefault="\"directed\"">
         <node id="\"n188\"" labels="\":Movie\"">
           <data key="\"labels\"">:Movie</data>
           <data key="\"title\"">The Matrix</data>
           <data key="\"tagline\"">Welcome to the Real World</data>
           <data key="\"released\"">1999</data>
         </node>
         <node id="\"n189\"" labels="\":Person\"">
           <data key="\"labels\"">:Person</data>
           <data key="\"born\"">1964</data>
           <data key="\"name\"">Keanu Reeves</data>
         </node>
         <node id="\"n190\"" labels="\":Person\"">
           <data key="\"labels\"">:Person</data>
           <data key="\"born\"">1967</data>
           <data key="\"name\"">Carrie-Anne Moss</data>
         </node>
         <node id="\"n191\"" labels="\":Person\"">
           <data key="\"labels\"">:Person</data>
           <data key="\"born\"">1961</data>
           <data key="\"name\"">Laurence Fishburne</data>
         </node>
         <node id="\"n192\"" labels="\":Person\"">
           <data key="\"labels\"">:Person</data>
           <data key="\"born\"">1960</data>
           <data key="\"name\"">Hugo Weaving</data>
         </node>
         <node id="\"n193\"" labels="\":Person\"">
           <data key="\"labels\"">:Person</data>
           <data key="\"born\"">1967</data>
           <data key="\"name\"">Lilly Wachowski</data>
         </node>
         <node id="\"n194\"" labels="\":Person\"">
           <data key="\"labels\"">:Person</data>
           <data key="\"born\"">1965</data>
           <data key="\"name\"">Lana Wachowski</data>
         </node>
         <node id="\"n195\"" labels="\":Person\"">
           <data key="\"labels\"">:Person</data>
           <data key="\"born\"">1952</data>
           <data key="\"name\"">Joel Silver</data>
         </node>
         <edge id="\"e267\"" source="\"n189\"" target="\"n188\"" label="\"ACTED_IN\"">
           <data key="\"label\"">ACTED_IN</data>
           <data key="\"roles\"">[\"Neo\"]</data>
         </edge>
         <edge id="\"e268\"" source="\"n190\"" target="\"n188\"" label="\"ACTED_IN\"">
           <data key="\"label\"">ACTED_IN</data>
           <data key="\"roles\"">[\"Trinity\"]</data>
         </edge>
         <edge id="\"e269\"" source="\"n191\"" target="\"n188\"" label="\"ACTED_IN\"">
           <data key="\"label\"">ACTED_IN</data>
           <data key="\"roles\"">[\"Morpheus\"]</data>
         </edge>
         <edge id="\"e270\"" source="\"n192\"" target="\"n188\"" label="\"ACTED_IN\"">
           <data key="\"label\"">ACTED_IN</data>
           <data key="\"roles\"">[\"Agent Smith\"]</data>
         </edge>
         <edge id="\"e271\"" source="\"n193\"" target="\"n188\"" label="\"DIRECTED\"">
           <data key="\"label\"">DIRECTED</data>
         </edge>
         <edge id="\"e272\"" source="\"n194\"" target="\"n188\"" label="\"DIRECTED\"">
           <data key="\"label\"">DIRECTED</data>
         </edge>
         <edge id="\"e273\"" source="\"n195\"" target="\"n188\"" label="\"PRODUCED\"">
           <data key="\"label\"">PRODUCED</data>
         </edge>
       </graph>
     </graphml>
      "

#### 6.4.5.2. Export specified nodes and relationships to GraphML

The `apoc.export.graphml.data` procedure exports the specified nodes and relationships to a CSV file or as a stream.

The following query exports all nodes with the `:Person` label with a `name` property that starts with `L` to the file `movies-l.csv`.

    MATCH (person:Person)
    WHERE person.name STARTS WITH "L"
    WITH collect(person) AS people
    CALL apoc.export.graphml.data(people, [], "movies-l.graphml", {})
    YIELD file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data
    RETURN file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data

Table 6.44. Results
file | source | format | nodes | relationships | properties | time | rows | batchSize | batches | done | data
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
"movies-l.csv" | "data: nodes(3), rels(0)" | "csv" | 3 | 0 | 6 | 2 | 3 | 20000 | 1 | TRUE | NULL

movies-l.graphml.

    <?xml version="1.0" encoding="UTF-8"?>
    <graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
    <key id="born" for="node" attr.name="born"/>
    <key id="name" for="node" attr.name="name"/>
    <key id="label" for="node" attr.name="label"/>
    <graph id="G" edgedefault="directed">
    <node id="n191" labels=":Person"><data key="labels">:Person</data><data key="born">1961</data><data key="name">Laurence Fishburne</data></node>
    <node id="n193" labels=":Person"><data key="labels">:Person</data><data key="born">1967</data><data key="name">Lilly Wachowski</data></node>
    <node id="n194" labels=":Person"><data key="labels">:Person</data><data key="born">1965</data><data key="name">Lana Wachowski</data></node>
    </graph>
    </graphml>

The following query returns a stream of all `ACTED_IN` relationships and the nodes with `Person` and `Movie` labels on either side of that relationship in the `data` column.

    MATCH (person:Person)-[actedIn:ACTED_IN]->(movie:Movie)
    WITH collect(DISTINCT person) AS people, collect(DISTINCT movie) AS movies, collect(actedIn) AS actedInRels
    CALL apoc.export.graphml.data(people + movies, actedInRels, null, {stream: true})
    YIELD file, nodes, relationships, properties, data
    RETURN file, nodes, relationships, properties, data;

Table 6.45. Results
file | nodes | relationships | properties | data
--- | --- | --- | --- | ---

NULL

5

4

15

    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
     <graphml xmlns="\"http://graphml.graphdrawing.org/xmlns\""
              xmlns:xsi="\"http://www.w3.org/2001/XMLSchema-instance\""
     xsi:schemaLocation="\"http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\"">
       <key id="\"born\"" for="\"node\"" attr.name="\"born\""/>
       <key id="\"name\"" for="\"node\"" attr.name="\"name\""/>
       <key id="\"tagline\"" for="\"node\"" attr.name="\"tagline\""/>
       <key id="\"label\"" for="\"node\"" attr.name="\"label\""/>
       <key id="\"title\"" for="\"node\"" attr.name="\"title\""/>
       <key id="\"released\"" for="\"node\"" attr.name="\"released\""/>
       <key id="\"roles\"" for="\"edge\"" attr.name="\"roles\""/>
       <key id="\"label\"" for="\"edge\"" attr.name="\"label\""/>
       <graph id="\"G\"" edgedefault="\"directed\"">
         <node id="\"n188\"" labels="\":Movie\"">
           <data key="\"labels\"">:Movie</data>
           <data key="\"title\"">The Matrix</data>
           <data key="\"tagline\"">Welcome to the Real World</data>
           <data key="\"released\"">1999</data>
         </node>
         <node id="\"n189\"" labels="\":Person\"">
           <data key="\"labels\"">:Person</data>
           <data key="\"born\"">1964</data>
           <data key="\"name\"">Keanu Reeves</data>
         </node>
         <node id="\"n190\"" labels="\":Person\"">
           <data key="\"labels\"">:Person</data>
           <data key="\"born\"">1967</data>
           <data key="\"name\"">Carrie-Anne Moss</data>
         </node>
         <node id="\"n191\"" labels="\":Person\"">
           <data key="\"labels\"">:Person</data>
           <data key="\"born\"">1961</data>
           <data key="\"name\"">Laurence Fishburne</data>
         </node>
         <node id="\"n192\"" labels="\":Person\"">
           <data key="\"labels\"">:Person</data>
           <data key="\"born\"">1960</data>
           <data key="\"name\"">Hugo Weaving</data>
         </node>
         <node id="\"n193\"" labels="\":Person\"">
           <data key="\"labels\"">:Person</data>
           <data key="\"born\"">1967</data>
           <data key="\"name\"">Lilly Wachowski</data>
         </node>
         <node id="\"n194\"" labels="\":Person\"">
           <data key="\"labels\"">:Person</data>
           <data key="\"born\"">1965</data>
           <data key="\"name\"">Lana Wachowski</data>
         </node>
         <node id="\"n195\"" labels="\":Person\"">
           <data key="\"labels\"">:Person</data>
           <data key="\"born\"">1952</data>
           <data key="\"name\"">Joel Silver</data>
         </node>
         <edge id="\"e267\"" source="\"n189\"" target="\"n188\"" label="\"ACTED_IN\"">
           <data key="\"label\"">ACTED_IN</data>
           <data key="\"roles\"">[\"Neo\"]</data>
         </edge>
         <edge id="\"e268\"" source="\"n190\"" target="\"n188\"" label="\"ACTED_IN\"">
           <data key="\"label\"">ACTED_IN</data>
           <data key="\"roles\"">[\"Trinity\"]</data>
         </edge>
         <edge id="\"e269\"" source="\"n191\"" target="\"n188\"" label="\"ACTED_IN\"">
           <data key="\"label\"">ACTED_IN</data>
           <data key="\"roles\"">[\"Morpheus\"]</data>
         </edge>
         <edge id="\"e270\"" source="\"n192\"" target="\"n188\"" label="\"ACTED_IN\"">
           <data key="\"label\"">ACTED_IN</data>
           <data key="\"roles\"">[\"Agent Smith\"]</data>
         </edge>
         <edge id="\"e271\"" source="\"n193\"" target="\"n188\"" label="\"DIRECTED\"">
           <data key="\"label\"">DIRECTED</data>
         </edge>
         <edge id="\"e272\"" source="\"n194\"" target="\"n188\"" label="\"DIRECTED\"">
           <data key="\"label\"">DIRECTED</data>
         </edge>
         <edge id="\"e273\"" source="\"n195\"" target="\"n188\"" label="\"PRODUCED\"">
           <data key="\"label\"">PRODUCED</data>
         </edge>
       </graph>
     </graphml>"

#### 6.4.5.3. Export virtual graph to GraphML

The `apoc.export.graphml.graph` procedure exports a virtual graph to a CSV file or as a stream.

The examples in this section are based on a virtual graph that contains all `PRODUCED` relationships and the nodes either side of that relationship. The query below creates a virtual graph and stores it in memory with the name `producers.cached` using Static Value Storage.

    MATCH path = (:Person)-[produced:PRODUCED]->(:Movie)
    WITH collect(path) AS paths
    CALL apoc.graph.fromPaths(paths, "producers", {})
    YIELD graph AS g
    CALL apoc.static.set("producers.cached", g)
    YIELD value
    RETURN value, g

Table 6.46. Results
value | g
--- | ---
NULL | {name: "producers", relationships: , nodes: [(:Person {name: "Joel Silver", born: 1952}), (:Movie {tagline: "Welcome to the Real World", title: "The Matrix", released: 1999})], properties: {}}

The following query exports the virtual graph from static value storage to the file `movies-producers.csv`.

    CALL apoc.export.graphml.graph(apoc.static.get("producers.cached"), "movies-producers.graphml", {});

Table 6.47. Results
file | source | format | nodes | relationships | properties | time | rows | batchSize | batches | done | data
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
"movies-producers.graphml" | "graph: nodes(2), rels(1)" | "csv" | 2 | 1 | 5 | 2 | 3 | 20000 | 1 | TRUE | NULL

movies-producers.graphml.

    <?xml version="1.0" encoding="UTF-8"?>
    <graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
    <key id="born" for="node" attr.name="born"/>
    <key id="name" for="node" attr.name="name"/>
    <key id="tagline" for="node" attr.name="tagline"/>
    <key id="label" for="node" attr.name="label"/>
    <key id="title" for="node" attr.name="title"/>
    <key id="released" for="node" attr.name="released"/>
    <key id="label" for="edge" attr.name="label"/>
    <graph id="G" edgedefault="directed">
    <node id="n195" labels=":Person"><data key="labels">:Person</data><data key="born">1952</data><data key="name">Joel Silver</data></node>
    <node id="n188" labels=":Movie"><data key="labels">:Movie</data><data key="title">The Matrix</data><data key="tagline">Welcome to the Real World</data><data key="released">1999</data></node>
    <edge id="e273" source="n195" target="n188" label="PRODUCED"><data key="label">PRODUCED</data></edge>
    </graph>
    </graphml>

The following query returns a streams of the virtual graph from static value storage to the `data` column.

    CALL apoc.export.graphml.graph(apoc.static.get("producers.cached"), null, {stream: true})
    YIELD file, nodes, relationships, properties, data
    RETURN file, nodes, relationships, properties, data;

Table 6.48. Results
file | nodes | relationships | properties | data
--- | --- | --- | --- | ---

NULL

2

1

5

    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
     <graphml
       xmlns="\"
       http://graphml.graphdrawing.org/xmlns\""="http://graphml.graphdrawing.org/xmlns\"""
       xmlns:xsi="\"
       http://www.w3.org/2001/XMLSchema-instance\""="http://www.w3.org/2001/XMLSchema-instance\"""
       xsi:schemaLocation="\"
       http://graphml.graphdrawing.org/xmlns="http://graphml.graphdrawing.org/xmlns"
       http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\""="http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\""">
       <key id="\" born\""="born\""" for="\" node\""="node\""" attr.name="\"/>
       <key id="\" name\""="name\""" for="\" node\""="node\""" attr.name="\"/>
       <key id="\" tagline\""="tagline\""" for="\" node\""="node\""" attr.name="\"/>
       <key id="\" label\""="label\""" for="\" node\""="node\""" attr.name="\"/>
       <key id="\" title\""="title\""" for="\" node\""="node\""" attr.name="\"/>
       <key id="\" released\""="released\""" for="\" node\""="node\""" attr.name="\"/>
       <key id="\" label\""="label\""" for="\" edge\""="edge\""" attr.name="\"/>
       <graph id="\" G\""="G\""" edgedefault="\" directed\""="directed\""">
         <node id="\" n195\""="n195\""" labels="\" :Person\""=":Person\""">
           <data key="\" labels\""="labels\""">:Person</data>
           <data key="\" born\""="born\""">1952</data>
           <data key="\" name\""="name\""">Joel Silver</data>
         </node>
         <node id="\" n188\""="n188\""" labels="\" :Movie\""=":Movie\""">
           <data key="\" labels\""="labels\""">:Movie</data>
           <data key="\" title\""="title\""">The Matrix</data>
           <data key="\" tagline\""="tagline\""">Welcome to the Real World</data>
           <data key="\" released\""="released\""">1999</data>
         </node>
         <edge id="\" e273\""="e273\""" source="\" n195\""="n195\""" target="\" n188\""="n188\""" label="\" PRODUCED\""="PRODUCED\""">
           <data key="\" label\""="label\""">PRODUCED</data>
         </edge>
       </graph>
     </graphml>
      "

#### 6.4.5.4. Export results of Cypher query to GraphML

The `apoc.export.csv.query` procedure exports the results of a Cypher query to a CSV file or as a stream.

The following query exports all `DIRECTED` relationships and the nodes with `Person` and `Movie` labels on either side of that relationship to the file `movies-directed.graphml`.

    WITH "MATCH path = (person:Person)-[directed:DIRECTED]->(movie)
          RETURN person, directed, movie" AS query
    CALL apoc.export.graphml.query(query, "movies-directed.graphml", {})
    YIELD file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data
    RETURN file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data;

Table 6.49. Results
file | source | format | nodes | relationships | properties | time | rows | batchSize | batches | done | data
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
"movies-directed.graphml" | "statement: nodes(3), rels(2)" | "graphml" | 3 | 2 | 7 | 2 | 5 | -1 | 0 | TRUE | NULL

The contents of `movies-directed.csv` are shown below:

movies-directed.graphml.

    <?xml version="1.0" encoding="UTF-8"?>
    <graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
    <key id="born" for="node" attr.name="born"/>
    <key id="name" for="node" attr.name="name"/>
    <key id="tagline" for="node" attr.name="tagline"/>
    <key id="label" for="node" attr.name="label"/>
    <key id="title" for="node" attr.name="title"/>
    <key id="released" for="node" attr.name="released"/>
    <key id="label" for="edge" attr.name="label"/>
    <graph id="G" edgedefault="directed">
    <node id="n188" labels=":Movie"><data key="labels">:Movie</data><data key="title">The Matrix</data><data key="tagline">Welcome to the Real World</data><data key="released">1999</data></node>
    <node id="n193" labels=":Person"><data key="labels">:Person</data><data key="born">1967</data><data key="name">Lilly Wachowski</data></node>
    <node id="n194" labels=":Person"><data key="labels">:Person</data><data key="born">1965</data><data key="name">Lana Wachowski</data></node>
    <edge id="e271" source="n193" target="n188" label="DIRECTED"><data key="label">DIRECTED</data></edge>
    <edge id="e272" source="n194" target="n188" label="DIRECTED"><data key="label">DIRECTED</data></edge>
    </graph>
    </graphml>

The following query returns a stream of all `DIRECTED` relationships and the nodes with `Person` and `Movie` labels on either side of that relationship.

    WITH "MATCH path = (person:Person)-[directed:DIRECTED]->(movie)
          RETURN person, directed, movie" AS query
    CALL apoc.export.graphml.query(query, null, {stream: true})
    YIELD file, nodes, relationships, properties, data
    RETURN file, nodes, relationships, properties, data;

Table 6.50. Results
file | nodes | relationships | properties | data
--- | --- | --- | --- | ---

NULL

3

2

7

    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
     <graphml xmlns="\"http://graphml.graphdrawing.org/xmlns\""
              xmlns:xsi="\"http://www.w3.org/2001/XMLSchema-instance\""
              xsi:schemaLocation="\"http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\"">
       <key id="\"born\"" for="\"node\"" attr.name="\"born\""/>
       <key id="\"name\"" for="\"node\"" attr.name="\"name\""/>
       <key id="\"tagline\"" for="\"node\"" attr.name="\"tagline\""/>
       <key id="\"label\"" for="\"node\"" attr.name="\"label\""/>
       <key id="\"title\"" for="\"node\"" attr.name="\"title\""/>
       <key id="\"released\"" for="\"node\"" attr.name="\"released\""/>
       <key id="\"label\"" for="\"edge\"" attr.name="\"label\""/>
       <graph id="\"G\"" edgedefault="\"directed\"">
         <node id="\"n188\"" labels="\":Movie\"">
           <data key="\"labels\"">:Movie</data>
           <data key="\"title\"">The Matrix</data>
           <data key="\"tagline\"">Welcome to the Real World</data>
           <data key="\"released\"">1999</data>
         </node>
         <node id="\"n193\"" labels="\":Person\"">
           <data key="\"labels\"">:Person</data>
           <data key="\"born\"">1967</data>
           <data key="\"name\"">Lilly Wachowski</data>
         </node>
         <node id="\"n194\"" labels="\":Person\"">
           <data key="\"labels\"">:Person</data>
           <data key="\"born\"">1965</data>
           <data key="\"name\"">Lana Wachowski</data>
         </node>
         <edge id="\"e271\"" source="\"n193\"" target="\"n188\"" label="\"DIRECTED\"">
           <data key="\"label\"">DIRECTED</data>
         </edge>
         <edge id="\"e272\"" source="\"n194\"" target="\"n188\"" label="\"DIRECTED\"">
           <data key="\"label\"">DIRECTED</data>
         </edge>
       </graph>
     </graphml>
      "