I'm trying to write out a graphML document with XOM in java, but I can't figure out how to get all of the namespace declarations correct. To have valid graphML, I need to have a root element that looks like the following:
<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.0/graphml.xsd">
I've been able to get most of this by doing
Element root = new Element("graphml");
root.setNamespaceURI("http://graphml.graphdrawing.org/xmlns");
root.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
The problem is the last element of this tag, the xsi:schemaLocation
. I can't figure out how to express this in XOM. I can't do it as a normal attribute, as that throws an exception(Attribute prefixes must be declared.
) and doing it as an additional namespace declaration also results in an exception(NCNames cannot contain colons
). Any ideas?