Date: January 21, 2006
<?xml version="1.0"?>
<graph>
<node id="1" label="http://www.example.org/" weight="2345">
<att name="title" value="Example Main Page"/>
<att name="mime" value="text/html"/>
<att name="size" value="2345"/>
<att name="date" value="Wed Jun 9 23:01:06 2000"/>
<att name="code" value="200"/>
</node>
<node id="2" label="http://www.example.org/software/" weight="1234">
<att name="title" value="Software Examples"/>
<att name="mime" value="text/html"/>
<att name="size" value="1234"/>
<att name="date" value="Wed Sep 19 13:11:23 2000"/>
<att name="code" value="200"/>
</node>
<edge label="Software" source="1" target="2"/>
</graph>
The metadata (or schema) of XGMML is described in xgmml.xsd. Usually, the schema is used to validate the XML data before processing the data. However, in our case we will not use the schema and assume the data given has already been validated.
You need to do the following:
import org.apache.xerces.parsers.DOMParser; import org.w3c.dom.*;
DOMParser p = new DOMParser();
p.parse("graph.xml");
Node root = p.getDocument().getDocumentElement();
In our case, root should point to a graph element.
Note the following:
The output of your program should be similar to the one below:
graph
node id=1 label=http://www.example.org/ weight=2345
att name=title value=Example Main Page
att name=mime value=text/html
att name=size value=2345
att name=date value=Wed Jun 9 23:01:06 2000
att name=code value=200
node id=2 label=http://www.example.org/software/ weight=1234
att name=title value=Software Examples
att name=mime value=text/html
att name=size value=1234
att name=date value=Wed Sep 19 13:11:23 2000
att name=code value=200
edge label=Software source=1 target=2