Read graphml

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

did you do

using GraphIO.GraphML

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

OK… How about this:

using Graphs
using GraphIO
using EzXML

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

The documentation could do with some work…

with this it gives the following error:

LoadError: UndefVarError: loadgraphs not defined

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

  [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. :slight_smile:

Putting it all together?

using Graphs
using GraphIO
using EzXML

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

Not really with this I got the following error:

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

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.

the code is simply the following

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

and the error message is

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

Package status?

LightGraphs should be Graphs I think.

unfortunately, either Graphs or Lightgraphs both give the same error

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

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
shows a similar method for loading a GraphML, which by [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.

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

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.

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

Yes, you should install it as usually.

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

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

and here is the graph

<?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

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

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

still with that I got an error messege:

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

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

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”