我正在使用gephi-toolkit编写java函数,它应该生成gefx格式的图形数据,作为输出流,而不是文件,以供进一步使用。
如果我使用CharArrayWriter或StringWriter - 所有xml标签都被格式化为特殊符号,我的输出如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<gexf xmlns="http://www.gexf.net/1.2draft" version="1.2" xmlns:viz="http://www.gexf.net/1.2draft/viz" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.gexf.net/1.2draft http://www.gexf.net/1.2draft/gexf.xsd">
<meta lastmodifieddate="2016-03-24">
<creator>Gephi 0.8.1</creator>
<description></description>
</meta>
<graph defaultedgetype="directed" mode="static">
<nodes>
<node id="1" label="n0">
<attvalues></attvalues>
<viz:size value="10.0"></viz:size>
<viz:position x="-206.8857" y="-18.469671" z="0.0"></viz:position>
<viz:color r="153" g="153" b="153"></viz:color>
</node>
<node id="2" label="n1">
<attvalues></attvalues>
<viz:size value="10.0"></viz:size>
<viz:position x="-29.136229" y="80.29351" z="0.0"></viz:position>
<viz:color r="153" g="153" b="153"></viz:color>
我应该使用什么来在输出端获取xml-streamamed数据?
当前代码:
//Export
ExportController ec = Lookup.getDefault().lookup(ExportController.class);
ExporterGEXF exp = (ExporterGEXF) ec.getExporter("gexf");
CharArrayWriter writer = new CharArrayWriter();
ec.exportWriter(writer, exp);
return writer;
答案 0 :(得分:0)
这个答案很有帮助: how to convert array byte to org.w3c.dom.Document
感谢harun!
工作代码是:
StringWriter strwriter = new StringWriter();
ec.exportWriter(strwriter, (CharacterExporter)exp);
String str = strwriter.getBuffer().toString();
byte[] arr = str.getBytes("UTF-8");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
return builder.parse(new ByteArrayInputStream(arr));