mxgraph - Rendering XML from draw.io as an image using mxCellRenderer -


i trying programmatically read in xml file generated draw.io, online flowchart/diagram creation service. draw.io built using mxgraph @ core, has been externally named jgraphx (thus tag on post), though class names have remained same.

this stackoverflow post shows how read in raw xml data file , convert mxgraph object, , this page of mxgraph javadocs describes how convert mxgraph object renderable image.

unfortunately me, however, despite following both guides, image "rendered" null , illegalargumentexception thrown (because image null). code follows:

string xmlfile = "work/test.xml"; string imagefile = "work/test.png"; mxgraph graph = new mxgraph();  try {     document doc = mxxmlutils.parsexml(mxutils.readfile(xmlfile));     mxcodec codec = new mxcodec(doc);     codec.decode(doc.getdocumentelement(), graph.getmodel()); } catch (ioexception e) {     e.printstacktrace(); }  renderedimage image = mxcellrenderer.createbufferedimage(graph, null, 1, \\     color.white, false, null);  try {     imageio.write(image, "png", new file(imagefile)); } catch (ioexception e) {     e.printstacktrace(); } 

as can see, code should read in xml data, create mxgraph object data, render mxgraph object image in current working directory. instead, however, nothing happens , no image created.

has ever experienced this? overlooking something? there better way i'm trying do? appreciated.

fyi, here pastebin sample xml file in case want try yourself.

with draw.io support guys, found answer: xml obfuscated, yes, not irretrievably so. compressed , needs decompressed. so:

  1. url decode
  2. inflate
  3. base64 decode

i found link 3 of above steps in 1 fell swoop: https://jgraph.github.io/drawio-tools/tools/convert.html.

once had decompressed xml code ran , generated expected output.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -