Create GraphML XML file with Java

With Blueprints it is very easy to create a XML file following the GraphML standard. All you need is this:

import com.tinkerpop.blueprints.pgm.Vertex;
public class App {
  private static final String OUTPUT_FILE = "./res/graph.graphml";
  public static void main(String[] args) throws Exception {
    OutputStream out = new FileOutputStream(OUTPUT_FILE);
    TinkerGraph graph = new TinkerGraph();
    Vertex source = graph.addVertex("1");
    Vertex target = graph.addVertex("2");
    graph.addEdge("3", source, target, "connection");
    GraphMLWriter writer = new GraphMLWriter(graph);

This is what you will get then:


<?xml version="1.0" ?>
<graphml xmlns="">
  <graph id="G" edgedefault="directed">
    <node id="2"></node>
    <node id="1"></node>
    <edge id="3" source="1" target="2" label="connection"></edge>

Create a link with an image in JavaScript

With JavaScript you can dynamically create every HTML element that you want. Here is an example on how to create a link with an image:

<!DOCTYPE html>
    <meta charset="utf-8" />
    <title>Create a link with an image in JavaScript</title>
    <style type="text/css">
      .googleImage{ border: 2px solid blue; }
    <script type="text/javascript">
      // Link
      var link = document.createElement('a');
      link.href = '';
      // Alternative:
      link.setAttribute('href', '');
      // Image
      var image = document.createElement('img');
      image.className = 'googleImage';
      image.src = '';
      // Create a link with an image inside
      // Display the link