# Read graphml

**URL:** https://discourse.julialang.org/t/read-graphml/91085
**Category:** General Usage
**Created:** [December 1, 2022, 9:52am UTC](https://discourse.julialang.org/t/read-graphml/91085 "2022-12-01T09:52:02Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![ahmad88](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmad88/32/32437_2.png) [@ahmad88](https://discourse.julialang.org/u/ahmad88)
#### Post date: [December 1, 2022, 9:52am UTC](https://discourse.julialang.org/t/read-graphml/91085/1 "2022-12-01T09:52:02Z")

</div>

I have graphs in Graphml format and I am trying to read the graph as follow

`loadgraph("tailorS1.graphml",graph,GraphIO.GraphML.GraphMLFormat())`

but I got the following error:  
`LoadError: UndefVarError: GraphML not defined`

---

<div class="post-metadata">

### Author: ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)
#### Post date: [December 1, 2022, 3:37pm UTC](https://discourse.julialang.org/t/read-graphml/91085/2 "2022-12-01T15:37:17Z")

</div>

did you do

```julia
using GraphIO.GraphML

```

---

<div class="post-metadata">

### Author: ![ahmad88](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmad88/32/32437_2.png) [@ahmad88](https://discourse.julialang.org/u/ahmad88)
#### Post date: [December 2, 2022, 10:08am UTC](https://discourse.julialang.org/t/read-graphml/91085/3 "2022-12-02T10:08:37Z")

</div>

yes, I am including  
`using GraphIO.GraphML`  
then  
`loadgraph("tailorS1.graphml",Gr,GraphIO.GraphML.GraphMLFormat())`  
still the same error messeage

---

<div class="post-metadata">

### Author: ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)
#### Post date: [December 2, 2022, 10:24am UTC](https://discourse.julialang.org/t/read-graphml/91085/4 "2022-12-02T10:24:19Z")

</div>

OK… How about this:

```julia
using Graphs
using GraphIO
using EzXML

d = loadgraphs("/tmp/test.gml", GraphMLFormat())

```

The documentation could do with some work…

---

<div class="post-metadata">

### Author: ![ahmad88](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmad88/32/32437_2.png) [@ahmad88](https://discourse.julialang.org/u/ahmad88)
#### Post date: [December 2, 2022, 11:07am UTC](https://discourse.julialang.org/t/read-graphml/91085/5 "2022-12-02T11:07:47Z")

</div>

with this it gives the following error:

`LoadError: UndefVarError: loadgraphs not defined`

---

<div class="post-metadata">

### Author: ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)
#### Post date: [December 2, 2022, 11:14am UTC](https://discourse.julialang.org/t/read-graphml/91085/6 "2022-12-02T11:14:34Z")

</div>

OK, this is as far as I go, not being a GraphIO user. Versions here are:

```nohighlight
  [8f5d6c58] EzXML v1.1.0
  [aa1b3936] GraphIO v0.6.0
  [86223c79] Graphs v1.7.4
  [dd2b58c7] GridGraphs v0.9.0
  [cd156443] Karnak v0.3.0
  [626554b9] MetaGraphs v0.7.1
  [46757867] NetworkLayout v0.4.4
  [47aef6b3] SimpleWeightedGraphs v1.2.1

```

I think you’re going to have to don your explorer’s outfit and start exploring the GraphIO source to find out how it works. 🙂

---

<div class="post-metadata">

### Author: ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)
#### Post date: [December 2, 2022, 11:38am UTC](https://discourse.julialang.org/t/read-graphml/91085/7 "2022-12-02T11:38:01Z")

</div>

Putting it all together?

```julia
using Graphs
using GraphIO
using EzXML

d = loadgraph("tailorS1.graphml", GraphIO.GraphML.GraphMLFormat())

```

---

<div class="post-metadata">

### Author: ![ahmad88](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmad88/32/32437_2.png) [@ahmad88](https://discourse.julialang.org/u/ahmad88)
#### Post date: [December 2, 2022, 1:18pm UTC](https://discourse.julialang.org/t/read-graphml/91085/8 "2022-12-02T13:18:07Z")

</div>

Not really with this I got the following error:

> LoadError: MethodError: no method matching loadgraph(::String, ::GraphIO.GraphML.GraphMLFormat)

---

<div class="post-metadata">

### Author: ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)
#### Post date: [December 2, 2022, 1:26pm UTC](https://discourse.julialang.org/t/read-graphml/91085/9 "2022-12-02T13:26:13Z")

</div>

Could you show the output of `] status` (ie your package status), and the code you’re running, and the complete error message… ? This might help people diagnose what’s going on.

---

<div class="post-metadata">

### Author: ![ahmad88](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmad88/32/32437_2.png) [@ahmad88](https://discourse.julialang.org/u/ahmad88)
#### Post date: [December 2, 2022, 1:33pm UTC](https://discourse.julialang.org/t/read-graphml/91085/10 "2022-12-02T13:33:53Z")

</div>

the code is simply the following

```julia
using Graphs
using GraphIO
 using EzXML
 d = loadgraph("tailorS1.graphml", GraphIO.GraphML.GraphMLFormat())

```

and the error message is

```julia
ERROR: LoadError: MethodError: no method matching loadgraph(::String, ::GraphIO.GraphML.GraphMLFormat)
Closest candidates are:
  loadgraph(::AbstractString) at C:\Users\Ahmad Anaqreh\.julia\packages\LightGraphs\IgJif\src\persistence\common.jl:18
  loadgraph(::AbstractString, ::AbstractString) at C:\Users\Ahmad Anaqreh\.julia\packages\LightGraphs\IgJif\src\persistence\common.jl:19
  loadgraph(::AbstractString, ::AbstractString, ::LightGraphs.AbstractGraphFormat) at C:\Users\Ahmad Anaqreh\.julia\packages\LightGraphs\IgJif\src\persistence\common.jl:13
  ...
Stacktrace:
 [1] top-level scope
   @ E:\Julia\test100.jl:4
 [2] eval
   @ .\boot.jl:373 [inlined]
 [3] include_string(mapexpr::typeof(identity), mod::Module, code::String, filename::String)
   @ Base .\loading.jl:1196
in expression starting at E:\Julia\test100.jl:4

```

---

<div class="post-metadata">

### Author: ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)
#### Post date: [December 2, 2022, 1:39pm UTC](https://discourse.julialang.org/t/read-graphml/91085/11 "2022-12-02T13:39:34Z")

</div>

Package status?

LightGraphs should be Graphs I think.

---

<div class="post-metadata">

### Author: ![ahmad88](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmad88/32/32437_2.png) [@ahmad88](https://discourse.julialang.org/u/ahmad88)
#### Post date: [December 2, 2022, 1:48pm UTC](https://discourse.julialang.org/t/read-graphml/91085/12 "2022-12-02T13:48:06Z")

</div>

unfortunately, either Graphs or Lightgraphs both give the same error

---

<div class="post-metadata">

### Author: ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)
#### Post date: [December 2, 2022, 7:42pm UTC](https://discourse.julialang.org/t/read-graphml/91085/13 "2022-12-02T19:42:10Z")

</div>

I had the same problem with reading a gml file and couldn’t read it until I passed `gname` as “digraph” to loadgraph:

```julia
G = loadgraph("data/gstrang_descendants.gml", "digraph", GraphIO.GML.GMLFormat())

```

This line [https://github.com/JuliaGraphs/GraphIO.jl/blob/master/src/GraphML/GraphML.jl#L133](https://github.com/JuliaGraphs/GraphIO.jl/blob/master/src/GraphML/GraphML.jl#L133)  
shows a similar method for loading a GraphML, which by [[http://graphml.graphdrawing.org/](http://graphml.graphdrawing.org/)], can be directed, undirected, mixed, hypergraph, and so on.  
From `?loadgraph` we find out that `gname is graph-format dependent`.  
Hence you should inspect what graph type is recorded in your graphml file.

---

<div class="post-metadata">

### Author: ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)
#### Post date: [December 3, 2022, 6:36pm UTC](https://discourse.julialang.org/t/read-graphml/91085/14 "2022-12-03T18:36:53Z")

</div>

I succeeded to read a GraphML file, after installing EzXML.jl, as it is required at  
[https://github.com/JuliaGraphs/GraphIO.jl/blob/master/src/deprecations.jl#L13](https://github.com/JuliaGraphs/GraphIO.jl/blob/master/src/deprecations.jl#L13)

```julia
using Graphs, GraphIO
using EzXML
#file downloaded from https://github.com/krlawrence/graph/blob/master/sample-data/air-routes-latest.graphml
G = loadgraph("data/air-routes-latest.graphml", "routes", GraphIO.GraphML.GraphMLFormat())

```

I identified the graph name, “routes”, searching for graph id in the graphml file.

---

<div class="post-metadata">

### Author: ![ahmad88](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmad88/32/32437_2.png) [@ahmad88](https://discourse.julialang.org/u/ahmad88)
#### Post date: [December 5, 2022, 9:40am UTC](https://discourse.julialang.org/t/read-graphml/91085/15 "2022-12-05T09:40:16Z")

</div>

Sorry, I don’t get the idea of installing EzXML.jl as required at the link you mentioned, I install it as any other Julia package

---

<div class="post-metadata">

### Author: ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)
#### Post date: [December 5, 2022, 11:47am UTC](https://discourse.julialang.org/t/read-graphml/91085/16 "2022-12-05T11:47:22Z")

</div>

Yes, you should install it as usually.

---

<div class="post-metadata">

### Author: ![ahmad88](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmad88/32/32437_2.png) [@ahmad88](https://discourse.julialang.org/u/ahmad88)
#### Post date: [December 5, 2022, 1:05pm UTC](https://discourse.julialang.org/t/read-graphml/91085/17 "2022-12-05T13:05:06Z")

</div>

Sorry, but I did exactly the same as you did and still get the same error message, here is my code :

```julia
using Graphs, GraphIO
using EzXML
G = loadgraph("tailorS1.graphml", "tailor", GraphIO.GraphML.GraphMLFormat())

```

and here is the graph

```julia
<?xml version="1.0"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns&#10;http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd&quot;&gt;&#10;">
	<graph id="G" edgedefault="undirected">
		<node id="0" />
		<node id="1" />
		<node id="2" />
		<node id="3" />
		<node id="4" />
		<node id="5" />
		<node id="6" />
		<node id="7" />
		<node id="8" />
		<node id="9" />
		<node id="10" />
		<node id="11" />
		<node id="12" />
		<node id="13" />
		<node id="14" />
		<node id="15" />
		<node id="16" />
		<node id="17" />
		<node id="18" />
		<node id="19" />
		<node id="20" />
		<node id="21" />
		<node id="22" />
		<node id="23" />
		<node id="24" />
		<node id="25" />
		<node id="26" />
		<node id="27" />
		<node id="28" />
		<node id="29" />
		<node id="30" />
		<node id="31" />
		<node id="32" />
		<node id="33" />
		<node id="34" />
		<node id="35" />
		<node id="36" />
		<node id="37" />
		<node id="38" />
		<edge id="0" source="0" target="1" />
		<edge id="1" source="0" target="2" />
		<edge id="2" source="3" target="1" />
		<edge id="3" source="3" target="2" />
		<edge id="4" source="3" target="0" />
		<edge id="5" source="4" target="0" />
		<edge id="6" source="5" target="0" />
		<edge id="7" source="5" target="6" />
		<edge id="8" source="7" target="0" />
		<edge id="9" source="8" target="1" />
		<edge id="10" source="8" target="0" />
		<edge id="11" source="8" target="6" />
		<edge id="12" source="8" target="5" />
		<edge id="13" source="9" target="1" />
		<edge id="14" source="9" target="2" />
		<edge id="15" source="9" target="0" />
		<edge id="16" source="9" target="3" />
		<edge id="17" source="9" target="6" />
		<edge id="18" source="9" target="4" />
		<edge id="19" source="9" target="5" />
		<edge id="20" source="9" target="8" />
		<edge id="21" source="10" target="2" />
		<edge id="22" source="10" target="0" />
		<edge id="23" source="10" target="3" />
		<edge id="24" source="10" target="6" />
		<edge id="25" source="10" target="4" />
		<edge id="26" source="10" target="11" />
		<edge id="27" source="10" target="9" />
		<edge id="28" source="12" target="0" />
		<edge id="29" source="12" target="3" />
		<edge id="30" source="12" target="6" />
		<edge id="31" source="12" target="4" />
		<edge id="32" source="12" target="9" />
		<edge id="33" source="12" target="10" />
		<edge id="34" source="13" target="3" />
		<edge id="35" source="13" target="8" />
		<edge id="36" source="13" target="9" />
		<edge id="37" source="14" target="0" />
		<edge id="38" source="15" target="2" />
		<edge id="39" source="15" target="0" />
		<edge id="40" source="15" target="3" />
		<edge id="41" source="15" target="4" />
		<edge id="42" source="15" target="5" />
		<edge id="43" source="15" target="7" />
		<edge id="44" source="15" target="8" />
		<edge id="45" source="15" target="9" />
		<edge id="46" source="15" target="10" />
		<edge id="47" source="15" target="12" />
		<edge id="48" source="15" target="14" />
		<edge id="49" source="16" target="15" />
		<edge id="50" source="17" target="7" />
		<edge id="51" source="17" target="10" />
		<edge id="52" source="17" target="13" />
		<edge id="53" source="18" target="0" />
		<edge id="54" source="18" target="3" />
		<edge id="55" source="18" target="4" />
		<edge id="56" source="18" target="9" />
		<edge id="57" source="18" target="10" />
		<edge id="58" source="18" target="13" />
		<edge id="59" source="18" target="14" />
		<edge id="60" source="18" target="15" />
		<edge id="61" source="18" target="17" />
		<edge id="62" source="19" target="8" />
		<edge id="63" source="19" target="10" />
		<edge id="64" source="19" target="15" />
		<edge id="65" source="19" target="18" />
		<edge id="66" source="20" target="14" />
		<edge id="67" source="20" target="18" />
		<edge id="68" source="20" target="19" />
		<edge id="69" source="20" target="21" />
		<edge id="70" source="22" target="13" />
		<edge id="71" source="22" target="15" />
		<edge id="72" source="22" target="16" />
		<edge id="73" source="22" target="17" />
		<edge id="74" source="22" target="18" />
		<edge id="75" source="22" target="19" />
		<edge id="76" source="22" target="20" />
		<edge id="77" source="23" target="9" />
		<edge id="78" source="23" target="15" />
		<edge id="79" source="24" target="15" />
		<edge id="80" source="25" target="17" />
		<edge id="81" source="25" target="26" />
		<edge id="82" source="25" target="20" />
		<edge id="83" source="27" target="13" />
		<edge id="84" source="27" target="14" />
		<edge id="85" source="27" target="20" />
		<edge id="86" source="27" target="22" />
		<edge id="87" source="27" target="25" />
		<edge id="88" source="28" target="12" />
		<edge id="89" source="28" target="15" />
		<edge id="90" source="28" target="18" />
		<edge id="91" source="28" target="19" />
		<edge id="92" source="28" target="23" />
		<edge id="93" source="29" target="15" />
		<edge id="94" source="29" target="17" />
		<edge id="95" source="29" target="18" />
		<edge id="96" source="30" target="10" />
		<edge id="97" source="30" target="13" />
		<edge id="98" source="30" target="15" />
		<edge id="99" source="30" target="22" />
		<edge id="100" source="30" target="27" />
		<edge id="101" source="30" target="29" />
		<edge id="102" source="31" target="5" />
		<edge id="103" source="31" target="12" />
		<edge id="104" source="31" target="15" />
		<edge id="105" source="31" target="18" />
		<edge id="106" source="31" target="19" />
		<edge id="107" source="31" target="22" />
		<edge id="108" source="31" target="24" />
		<edge id="109" source="31" target="29" />
		<edge id="110" source="32" target="8" />
		<edge id="111" source="32" target="18" />
		<edge id="112" source="32" target="23" />
		<edge id="113" source="32" target="27" />
		<edge id="114" source="32" target="28" />
		<edge id="115" source="32" target="30" />
		<edge id="116" source="33" target="9" />
		<edge id="117" source="33" target="15" />
		<edge id="118" source="33" target="18" />
		<edge id="119" source="33" target="22" />
		<edge id="120" source="33" target="25" />
		<edge id="121" source="33" target="29" />
		<edge id="122" source="33" target="30" />
		<edge id="123" source="33" target="31" />
		<edge id="124" source="33" target="32" />
		<edge id="125" source="34" target="12" />
		<edge id="126" source="34" target="27" />
		<edge id="127" source="34" target="30" />
		<edge id="128" source="34" target="31" />
		<edge id="129" source="34" target="32" />
		<edge id="130" source="34" target="33" />
		<edge id="131" source="35" target="10" />
		<edge id="132" source="35" target="28" />
		<edge id="133" source="35" target="29" />
		<edge id="134" source="35" target="30" />
		<edge id="135" source="35" target="31" />
		<edge id="136" source="35" target="32" />
		<edge id="137" source="35" target="33" />
		<edge id="138" source="35" target="34" />
		<edge id="139" source="36" target="15" />
		<edge id="140" source="36" target="29" />
		<edge id="141" source="36" target="31" />
		<edge id="142" source="36" target="33" />
		<edge id="143" source="36" target="35" />
		<edge id="144" source="37" target="15" />
		<edge id="145" source="37" target="27" />
		<edge id="146" source="37" target="28" />
		<edge id="147" source="37" target="29" />
		<edge id="148" source="37" target="31" />
		<edge id="149" source="37" target="33" />
		<edge id="150" source="37" target="34" />
		<edge id="151" source="37" target="35" />
		<edge id="152" source="37" target="36" />
		<edge id="153" source="38" target="28" />
		<edge id="154" source="38" target="29" />
		<edge id="155" source="38" target="31" />
		<edge id="156" source="38" target="32" />
		<edge id="157" source="38" target="33" />
	</graph>
</graphml>

```

Maybe I am doing somthing not ok or the graph is not ok

---

<div class="post-metadata">

### Author: ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)
#### Post date: [December 5, 2022, 1:24pm UTC](https://discourse.julialang.org/t/read-graphml/91085/18 "2022-12-05T13:24:26Z")

</div>

Your graph id is “G”, hence pass “G” as gname to loadgraph:

```julia
G = loadgraph("tailorS1.graphml", "G", GraphIO.GraphML.GraphMLFormat())

```

 ![graph-id](https://global.discourse-cdn.com/julialang/original/3X/b/a/ba76bfba8b6aed53a9e2893cedf83bf14f31693e.png)

---

<div class="post-metadata">

### Author: ![ahmad88](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmad88/32/32437_2.png) [@ahmad88](https://discourse.julialang.org/u/ahmad88)
#### Post date: [December 5, 2022, 1:27pm UTC](https://discourse.julialang.org/t/read-graphml/91085/19 "2022-12-05T13:27:20Z")

</div>

still with that I got an error messege:

`G= loadgraph("tailorS1.graphml", "G", GraphIO.GraphML.GraphMLFormat())`

```julia
ERROR: LoadError: MethodError: no method matching loadgraph(::String, ::String, ::GraphIO.GraphML.GraphMLFormat)
Closest candidates are:
  loadgraph(::AbstractString, ::AbstractString) at C:\Users\Ahmad Anaqreh\.julia\packages\LightGraphs\IgJif\src\persistence\common.jl:19
  loadgraph(::AbstractString, ::AbstractString, ::LightGraphs.AbstractGraphFormat) at C:\Users\Ahmad Anaqreh\.julia\packages\LightGraphs\IgJif\src\persistence\common.jl:13
  loadgraph(::AbstractString) at C:\Users\Ahmad Anaqreh\.julia\packages\LightGraphs\IgJif\src\persistence\common.jl:18
  ...
Stacktrace:
 [1] top-level scope
   @ E:\Julia\test100.jl:4
 [2] eval
   @ .\boot.jl:373 [inlined]
 [3] include_string(mapexpr::typeof(identity), mod::Module, code::String, filename::String)
   @ Base .\loading.jl:1196
in expression starting at E:\Julia\test100.jl:4

```

---

<div class="post-metadata">

### Author: ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)
#### Post date: [December 5, 2022, 1:33pm UTC](https://discourse.julialang.org/t/read-graphml/91085/20 "2022-12-05T13:33:11Z")

</div>

I think you have an old version of GraphIO or Graphs:

I have GraphIO version = “0.6.0”, Graphs version = “1.7.4”, and EzXML “1.1.0”

[Next page](https://discourse.julialang.org/t/read-graphml/91085.md?page=2)
