Has the GraphML standard been updated?

I downloaded the Rome database from the link.

enter image description here

The files in it are stored in the "GraphML" format. However, I am unable to import it into Mathematica or the YEd software. I would like to know what is happening and how to import them correctly. A similar unsolved issue can be found at the following link:


Import::fmterr: Cannot import data as GraphML format.

Example (grafo113.28.graphml):

<?xml version="1.0" encoding="UTF-8"?>
<!-- This file was written by the internal XML-Handler of Y-Files.-->
<!DOCTYPE graphml SYSTEM "http://www.graphdrawing.org/dtds/graphml.dtd">
<graph edgedefault="undirected" id="G">
<node id="n0"/>
<node id="n1"/>
<node id="n2"/>
<node id="n3"/>
<node id="n4"/>
<node id="n5"/>
<node id="n6"/>
<node id="n7"/>
<node id="n8"/>
<node id="n9"/>
<node id="n10"/>
<node id="n11"/>
<node id="n12"/>
<node id="n13"/>
<node id="n14"/>
<node id="n15"/>
<node id="n16"/>
<node id="n17"/>
<node id="n18"/>
<node id="n19"/>
<node id="n20"/>
<node id="n21"/>
<node id="n22"/>
<node id="n23"/>
<node id="n24"/>
<node id="n25"/>
<node id="n26"/>
<node id="n27"/>
<edge id="e0" source="n1" target="n12"/>
<edge id="e1" source="n12" target="n2"/>
<edge id="e2" source="n12" target="n0"/>
<edge id="e3" source="n0" target="n14"/>
<edge id="e4" source="n14" target="n3"/>
<edge id="e5" source="n20" target="n8"/>
<edge id="e6" source="n3" target="n15"/>
<edge id="e7" source="n3" target="n16"/>
<edge id="e8" source="n16" target="n5"/>
<edge id="e9" source="n3" target="n17"/>
<edge id="e10" source="n3" target="n18"/>
<edge id="e11" source="n19" target="n7"/>
<edge id="e12" source="n7" target="n21"/>
<edge id="e13" source="n4" target="n15"/>
<edge id="e14" source="n21" target="n9"/>
<edge id="e15" source="n9" target="n13"/>
<edge id="e16" source="n9" target="n22"/>
<edge id="e17" source="n22" target="n11"/>
<edge id="e18" source="n23" target="n3"/>
<edge id="e19" source="n18" target="n7"/>
<edge id="e20" source="n18" target="n24"/>
<edge id="e21" source="n24" target="n6"/>
<edge id="e22" source="n25" target="n23"/>
<edge id="e23" source="n25" target="n24"/>
<edge id="e24" source="n25" target="n13"/>
<edge id="e25" source="n19" target="n16"/>
<edge id="e26" source="n25" target="n26"/>
<edge id="e27" source="n26" target="n10"/>
<edge id="e28" source="n27" target="n13"/>
<edge id="e29" source="n27" target="n8"/>
<edge id="e30" source="n7" target="n26"/>

It looks like Syed is right. But I'm not sure what's behind the Import function. So now I don't understand why deleting that line <!DOCTYPE graphml SYSTEM "http://www.graphdrawing.org/dtds/graphml.dtd"> is OK.

  • 3
    $\begingroup$ This seems to be an older file. Remove the <!DOCTYPE... line and try again. $\endgroup$
    – Syed
    Feb 23, 2023 at 14:53
  • $\begingroup$ Yes, indeed. I'm not sure why this line ` <!DOCTYPE... ` leads to destruction. I don't know exactly how this function works, right. $\endgroup$
    – licheng
    Feb 23, 2023 at 15:24
  • 2
    $\begingroup$ It fails with Import[..., "XML"] as well, unless specifying "ReadDTD" -> False. But that option cannot be used with Import[..., "GraphML"], so yes: find a way to remove that line. E.g., ImportString[ StringRiffle[ Select[StringSplit[Import[file, "String"], "\n"], Not@*StringStartsQ["<!DOCTYPE"]], "\n"], "GraphML" ] $\endgroup$
    – Szabolcs
    Feb 23, 2023 at 18:31

1 Answer 1


Understanding the Problem

"GraphML" is an XML format. All these files start with

<?xml version="1.0" encoding="UTF-8"?>
<!-- This file was written by the internal XML-Handler of Y-Files.-->
<!DOCTYPE graphml SYSTEM "http://www.graphdrawing.org/dtds/graphml.dtd">

The "!DOCTYPE" declaration above contains a reference to a Document Type Definition (DTD) file. The purpose of a DTD is to define the structure and the legal elements and attributes of an XML document. An XML document validated against a DTD is both "Well Formed" and "Valid".

The URL for the Document Type Definition file "http://www.graphdrawing.org/dtds/graphml.dtd" is no longer valid, and needs to be replaced, or its reference deleted as mentioned by @Syed in the comments.

(* Not Found  
The requested URL /dtds/graphml.dtd was not found on this server. *)


@Szabolcs showed already how to delete the invalid line.

Here I Import one of the "rome/grafo1049.21.graphml" file as a "String", StringReplace the invalid URL with a valid URL for the "graphml.dtd" file, and then ImportString in the "GraphML" format.

            , {"TAR", "rome/grafo1049.21.graphml", "String"}
    , "http://www.graphdrawing.org/dtds/graphml.dtd" -> "http://graphml.graphdrawing.org/dtds/1.0rc/graphml.dtd"

enter image description here

You can replace the URL "http://www.graphdrawing.org/download/rome-graphml.tgz" with the local path to your downloaded file.


By the way, notice that you don't need to unpack your "rome-graphml.tgz" file to Import the files inside. Here I don't even download the whole file.

You can first just get the file names and then Import only the one you need directly, as shown above.

fileNameList = Import[
  , {"TAR", "FileNames"}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.