Reputation: 491
I want to execute an operation that is an inversion of what i do when forming xmlString in mxGraph().
mxGraph graph = new mxGraph();
Object parent = graph.GetDefaultParent();
graph.Model.BeginUpdate();
try
{
Object v1 = graph.InsertVertex(parent, null, "Hello,", 20, 20, 80, 30);
Object v2 = graph.InsertVertex(parent, null, "World!", 200, 150, 80, 30);
Object e1 = graph.InsertEdge(parent, null, "Edge", v1, v2);
}
finally
{
graph.Model.EndUpdate();
}
mxCodec codec = new mxCodec();
Xml = mxUtils.GetXml(codec.Encode(graph.Model));
var xmlString = mxUtils.GetXml(xml);
I'm trying to execute inverse operation.
XmlDocument doc = mxUtils.ParseXml(xmlString);
mxGraph graphNew = new mxGraph();
var decoder = new mxCodec(doc);
decoder.Decode(doc, graphNew.Model);
Object parentNew = graphNew.GetDefaultParent();
But the object "parentNew" has no children.
Upvotes: 4
Views: 1389
Reputation: 149
I just encountered this myself and was able to solve it.
decoder.Decode(doc, graphNew.Model);
should be:
decoder.Decode(doc.DocumentElement, graphNew.getModel());
In addition to doc.DocumentElement
, you also need to use graphNew.getModel()
, not just graphNew.model
.
As per this documentation
Also, you do not need to create a new graph. Insert your existing graph into the second parameter of Decode
.
Upvotes: 0
Reputation: 11
this code:
decoder.Decode(doc, graphNew.Model);
should be replaced with this code below:
decoder.Decode(doc.DocumentElement, graphNew.Model);
Upvotes: 1