GraphML Default Extension Mechanism

The GraphML default extension mechanism allows to declare so-called GraphML attributes that can be used to conveniently store additional information in a GraphML file. In its original form, this mechanism directly supports additional data of type bool, int, long, float, double, and string.

A GraphML attribute is declared using the <key> element which comprises a unique identifier as well as scope, name, and the domain of values (i.e., the actual type) for the attribute. Table 4.1, “XML attributes for GraphML <key> element” lists the set of XML attributes and describes their function within the declaration of a GraphML attribute. Note that in a GraphML file, <key> elements must be placed before any <graph> element.

Table 4.1. XML attributes for GraphML <key> element

XML Attribute Value Domain Description
id NMTOKEN Uniquely identifies the GraphML attribute declaration within a GraphML file. Required to enable the GraphML attribute look-up mechanism.
for one of "all", "graph", "node", "edge", or "port" Determines the scope of the GraphML attribute.
attr.name NMTOKEN Identifying name for the GraphML attribute that can be used by an application.
attr.type one of "boolean", "int", "long", "float", "double", "string", or "complex" Determines the domain for the values (i.e., the actual type) of the GraphML attribute.

Actual values for a GraphML attribute are defined using the <data> element which is nested within the GraphML elements <graph>, <node>, <edge>, or <port>. Required with each <data> element is XML attribute key which is used by a look-up mechanism to find the proper GraphML attribute declaration for the contents of a given <data> element. See also Table 4.2, “XML attribute for GraphML <data> element” for a brief explanation of XML attribute key.

Table 4.2. XML attribute for GraphML <data> element

XML Attribute Value Domain Description
key NMTOKEN Refers to the declaration of a GraphML attribute by matching its unique ID, i.e., the value given for the id attribute of a GraphML <key> element.

This GraphML attribute look-up mechanism is responsible for matching the value given for the key attribute of a <data> element to the unique ID defined by the id attribute of a <key> element. The mapping that is established by this match is essential for delegating the parsing of a given <data> element to the proper parser code that handles the specific contents. Example 4.3, “GraphML attribute look-up mechanism” shows the correct set-up to refer to a specific GraphML attribute when defining its values using the <data> element.

Example 4.3. GraphML attribute look-up mechanism

<!-- Declaration of a GraphML attribute. -->
<key id="someValidIdentifier" ... />

<!-- Referring to a specific GraphML attribute by matching the (unique) -->
<!-- identifier of its declaration. -->
<data key="someValidIdentifier">
...
</data>