Identifying graph schema in GraphML 

How to create a graph database schema using GraphML.

Defining the vertices and edges along with their properties is a critical first step in creating a graph database in GraphML. GraphML is an XML format that identifies vertices and edges. The first step in defining a graph in GraphML involves defining the vertex and edge properties. Note that a drawback of using GraphML is that indexes cannot be defined.

Procedure

  1. The GraphML header in the file identifies XML information:
    <?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.1/graphml.xsd">
  2. Create a graph instance to identify schema in a new file.
    <graph id="graph" edgedefault="directed">
  3. Define the vertex properties.
    <key id="labelV" for="node" attr.name="labelV" attr.type="string"/>
    <key id="id" for="node" attr.name="id" attr.type="int" />
    <key id="aname" for="node" attr.name="aname" attr.type="string"/>
    <key id="gender" for="node" attr.name="gender" attr.type="string"/>
    <key id="recipeTitle" for="node" attr.name="recipeTitle" attr.type="string" />
    <key id="instructions" for="node" attr.name="instructions" attr.type="string" />
    <key id="bookTitle" for="node" attr.name="bookTitle" attr.type="string" />
    <key id="publishDate" for="node" attr.name="publishDate" attr.type="int" />
    <key id="ISBN" for="node" attr.name="ISBN" attr.type="string" />
    <key id="iName" for="node" attr.name="iName" attr.type="string" />
    <key id="mealTitle" for="node" attr.name="mealTitle" attr.type="string"/>
    <key id="mCreateDate" for="node" attr.name="mCreateDate" attr.type="string"/>
    <key id="calories" for="node" attr.name="calories" attr.type="int"/>
    <key id="revname" for="node" attr.name="revname" attr.type="string"/>

    The property with id labelV is always defined, as each vertex has a vertex label. Additional vertex properties are defined with an ID, attribute name, and attribute type. Note that the for="node" statement defines each property as a vertex property.

  4. Define the edge properties.
    <key id="labelE" for="edge" attr.name="labelE" attr.type="string"/>
    <key id="stars" for="edge" attr.name="stars" attr.type="string"/>
    <key id="ratedDate" for="edge" attr.name="ratedDate" attr.type="string"/>
    <key id="comment" for="edge" attr.name="comment" attr.type="string"/>
    <key id="amount" for="edge" attr.name="amount" attr.type="string"/>

    The property with id labelE is always defined, as each edge has a edge identifier denoted by the label. Additional edge properties are defined with an ID, attribute name, and attribute type. Note that the for="edge" statement defines each property as a edge property.