我正在尝试使用Java中的XOM编写GraphML文档,但我无法弄清楚如何正确获取所有命名空间声明。为了拥有有效的GraphML,我需要具有以下外观的根元素:
<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">
我通过实践已经掌握了大部分技术细节
Element root = new Element("graphml");
root.setNamespaceURI("http://graphml.graphdrawing.org/xmlns");
root.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
问题在于此标签的最后一个元素,即
xsi:schemaLocation
。我无法想出如何在 XOM 中表达这一点。我不能将其作为普通属性处理,因为那会抛出异常(属性前缀必须声明。
),并且将其作为其他命名空间声明也会导致异常(NCNames 不能包含冒号
)。有什么建议吗?