Writing GraphML with XOM?

I am trying to write a graphML document with XOM in java, but I cannot figure out how to correctly get all namespace declarations. To have a valid graphML, I need to have a root element that looks like this:

<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 was 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 - the last element of the tag xsi:schemaLocation. I cannot figure out how to express this in XOM. I cannot do this as a regular attribute, as it throws an exception ( Attribute prefixes must be declared.) and does it as an additional namespace declaration also results in an exception ( NCNames cannot contain colons). Any ideas?

+3
source share
1 answer

. URI xsi:schemaLocation. , prefixed , .

root.addAttribute(new Attribute("xsi:schemaLocation",
    "http://www.w3.org/2001/XMLSchema-instance",
    "http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd"));

Attribute(String name, String URI, String value)

+3

Source: https://habr.com/ru/post/1723697/


All Articles