我想执行一个操作,它是我在mxGraph()中形成xmlString时所做的反转. mxGraph graph = new mxGraph(); Object parent = graph.GetDefaultParent(); graph.Model.BeginUpdate(); try { Object v1 = graph.InsertVertex(parent, null, "Hell
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);
我正在尝试执行逆操作.
XmlDocument doc = mxUtils.ParseXml(xmlString); mxGraph graphNew = new mxGraph(); var decoder = new mxCodec(doc); decoder.Decode(doc, graphNew.Model); Object parentNew = graphNew.GetDefaultParent();
但是对象“parentNew”没有孩子.
这段代码:decoder.Decode(doc, graphNew.Model);
应该用以下代码替换:
decoder.Decode(doc.DocumentElement, graphNew.Model);