Inserting data using GraphML

After the vertex and edge properties are defined, the graph data can be defined. Because GraphML is XML data, the node element <node ...> is used to define a vertex, and the edge element <edge ...> is used to define an edge.

In general, GraphML files have been written from graphs that have previously been created. In DSE Graph, the vertex and edge identification is composed of three parts plus a label value that are created when a vertex is added with another method like a Gremlin command. These instruction dissect a GraphML file to explain the features.

  1. Add vertex data by appending to the GraphML file started in Identifying graph schema, add vertex data. Each vertex is given a vertex label and some properties. Each vertex property is a key-value pair, using the previously created property keys.

    <node id="{~label=meal, member_id=21, community_id=1579328896}">
      <data key="labelV">meal</data>
      <data key="name">Saturday Feast</data>
      <data key="calories">1000</data>
      <data key="timestamp">2015-11-30T00:00:00Z</data>
    </node>

    Each vertex must have an identifier. Generally, a label is defined to denote the type of vertex. In this example, the vertex shown is an meal vertex. Subsequent properties are defined in this example, such as name and calories.

  2. Add an edge.

    <edge id="{
      out_vertex={~label=meal, member_id=22, community_id=1579328896},
      local_id=62b12e83-0e6a-11e6-b5e4-0febe4822aa4,
      in_vertex={~label=book, member_id=27, community_id=1579328896}, ~type=includedIn}"
      source="{~label=meal, member_id=22, community_id=1579328896}"
      target="{~label=book, member_id=27, community_id=1579328896}">
      <data key="labelE">includedIn</data>
    </edge>

    Each edge must have an identifier. In addition, the source and target vertices must be identified to define the starting vertex and the ending vertex of an edge. As with the vertices, a label is defined to denote the type of edge.

  3. A GraphML file has ending tags to close the XML statements.

    </graph></graphml>
  4. Close and name the GraphML file, using a graphml file extension.

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com