Beispiel #1
0
        public void LoadFromXml(string file)
        {
            XmlDocument   xdoc = new XmlDocument();
            XmlTextReader xtr  = new XmlTextReader(file);

            xdoc.Load(xtr);
            int n = xdoc.DocumentElement.ChildNodes.Count;

            for (int i = 0; i < n; i++)
            {
                XmlElement xe             = (XmlElement)xdoc.DocumentElement.ChildNodes[i];
                string     drawObjectType = xe.GetAttribute("Type");
                if (drawObjectType.Equals("VisualGraph"))
                {
                    DocFromXml(xe);
                }
                else
                {
                    DrawObject drawObject = null;
                    switch (drawObjectType)
                    {
                    case "DrawEllipse":
                        drawObject = (DrawObject)Activator.CreateInstance(typeof(DrawEllipse));
                        break;

                    case "DrawLine":
                        drawObject = (DrawObject)Activator.CreateInstance(typeof(DrawLine));
                        break;

                    case "DrawPic":
                        drawObject = (DrawObject)Activator.CreateInstance(typeof(DrawPic));
                        break;

                    case "DrawRectangle":
                        drawObject = (DrawObject)Activator.CreateInstance(typeof(DrawRectangle));
                        break;

                    case "DrawText":
                        drawObject = (DrawObject)Activator.CreateInstance(typeof(DrawText));
                        break;
                    }
                    drawObject.ReadFromXml(xe);
                    ObjList.AddObject(drawObject);
                }
            }
        }
        public void LoadFromXml(string file)
        {
            XmlDocument   xdoc = new XmlDocument();
            XmlTextReader xtr  = new XmlTextReader(file);

            xdoc.Load(xtr);
            int n = xdoc.DocumentElement.ChildNodes.Count;

            for (int i = 0; i < n; i++)
            {
                XmlElement xe             = (XmlElement)xdoc.DocumentElement.ChildNodes[i];
                string     drawObjectType = xe.GetAttribute("Type");
                if (drawObjectType.Equals("VisualGraph"))
                {
                    DocFromXml(xe);
                }
                else
                {
                    DrawObject drawObject = (DrawObject)Activator.CreateInstance("VisualGraph", "VisualGraph." + drawObjectType).Unwrap();
                    drawObject.ReadFromXml(xe);
                    ObjList.AddObject(drawObject);
                }
            }
        }