XML for graphing using the JGraphX ​​API

I need to parse XML into a graph in JGraphX ​​using Java. I get this XML from the JGraphX ​​library and must install the graph again with this XML. Is there any JGraphX ​​library method that converts XML to graph? I have this code below to get the XML from the graph:

try { System.out.println("call xml getting code"); mxCodec codec = new mxCodec(); String xml = mxUtils.getXml(codec.encode(graph1.getModel())); java.io.FileWriter fw = new java.io.FileWriter("E:\\my-file.xml"); fw.write(xml); fw.close(); } catch(Exception ex) { System.out.println("ERROR : "+ex.getMessage()); } 

So, is there a way to get a graph from this XML? Otherwise, what should I do to generate a chart? If I try to create a graph by reading the XML one by one, it may take some time with complex algorithms, so I tried to find another library method.

+2
source share
1 answer

This should read it from the specified Path to the new mxGraph

 mxGraph graph = new mxGraph(); try { Document document = mxXmlUtils.parseXml(mxUtils.readFile(filePath)); mxCodec codec = new mxCodec(document); codec.decode(document.getDocumentElement(), graph.getModel()); } catch (Exception ex) { ex.printStackTrace(); } 
0
source

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


All Articles