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); }
/// <summary> /// Reads the specified child into the given object. /// </summary> protected void DecodeChild(mxCodec dec, XmlNode child, Object obj) { string fieldname = GetFieldName(((XmlElement)child).GetAttribute("as")); if (fieldname == null || !IsExcluded(obj, fieldname, child, false)) { Object template = GetFieldTemplate(obj, fieldname, child); Object value = null; if (child.Name.Equals("add")) { value = ((XmlElement)child).GetAttribute("value"); if (value == null) { value = child.InnerText; } } else { value = dec.Decode(child, template); } AddObjectValue(obj, fieldname, value, template); } }
/// <summary> /// /// </summary> /// <param name="dec">Codec that controls the encoding/decoding process.</param> /// <param name="node">XML node to be checked.</param> /// <param name="into">Optional object to pass-thru to the codec.</param> /// <returns>Returns true if the given node was processed as an include.</returns> public bool ProcessInclude(mxCodec dec, XmlNode node, Object into) { if (node.NodeType == XmlNodeType.Element && node.Name.ToLower().Equals("include")) { string name = ((XmlElement)node).GetAttribute("name"); if (name != null) { XmlNode xml = mxUtils.LoadDocument(name).DocumentElement; if (xml != null) { dec.Decode(xml, into); } } return(true); } return(false); }
/// <summary> /// /// </summary> /// <param name="dec">Codec that controls the encoding/decoding process.</param> /// <param name="node">XML node to be checked.</param> /// <param name="into">Optional object to pass-thru to the codec.</param> /// <returns>Returns true if the given node was processed as an include.</returns> public bool ProcessInclude(mxCodec dec, XmlNode node, Object into) { if (node.NodeType == XmlNodeType.Element && node.Name.ToLower().Equals("include")) { string name = ((XmlElement)node).GetAttribute("name"); if (name != null) { XmlNode xml = mxUtils.LoadDocument(name).DocumentElement; if (xml != null) { dec.Decode(xml, into); } } return true; } return false; }