public static void Main() { // Creates graph with model mxGraph graph = new mxGraph(); // Adds cells into the model Object parent = graph.GetDefaultParent(); graph.Model.BeginUpdate(); Object v1, v2, e1; try { v1 = graph.InsertVertex(parent, null, "Hello", 20, 20, 80, 30); v2 = graph.InsertVertex(parent, null, "World!", 200, 150, 80, 30); e1 = graph.InsertEdge(parent, null, "e1", v1, v2); } finally { graph.Model.EndUpdate(); } mxCodec codec = new mxCodec(); XmlNode node = codec.Encode(graph.Model); string xml1 = mxUtils.GetPrettyXml(node); codec = new mxCodec(); Object model = codec.Decode(node); codec = new mxCodec(); node = codec.Encode(model); string xml2 = mxUtils.GetPrettyXml(node); Console.WriteLine("mxCodecTest Passed: "+(xml1.Equals(xml2))); Thread.Sleep(100000); }
protected void Page_Load(object sender, EventArgs e) { // Creates an instance of a graph to add vertices and edges. The instance can // then be used to create the corresponding XML using a codec. Note that this // is only required if a graph is programmatically created. If the XML for the // graph is already at hand, it can be sent directly here. mxGraph graph = new mxGraph(); Object parent = graph.GetDefaultParent(); // Adds vertices and edges to the graph. 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(); } // Encodes the model into XML and passes the resulting XML string into a page // variable, so it can be read when the page is rendered on the server. Note // that the page instance is destroyed after the page was sent to the client. mxCodec codec = new mxCodec(); Xml = mxUtils.GetXml(codec.Encode(graph.Model)); }
/// <summary> /// Writes the given value as a child node of the given node. /// </summary> protected void WriteComplexAttribute(mxCodec enc, Object obj, string attr, Object value, XmlNode node) { XmlNode child = enc.Encode(value); if (child != null) { if (attr != null) { mxCodec.SetAttribute(child, "as", attr); } node.AppendChild(child); } else { Trace.WriteLine("mxObjectCodec.encode: No node for " + GetName() + "." + attr + ": " + value); } }