示例#1
0
        public void ReadLayout(Control f)
        {
            MemoryStream s = SaveLoadLayout.LoadFormDB(f.Name);

            if (s == null)
            {
                return;
            }
            StreamReader sr        = new StreamReader(s);
            string       cleandown = sr.ReadToEnd();

            cleandown = "<DOCUMENT_ELEMENT>" + cleandown + "</DOCUMENT_ELEMENT>";

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(cleandown);

            foreach (XmlNode node in doc.DocumentElement.ChildNodes)
            {
                if (node.Name.Equals("Object"))
                {
                    ReadObject(node, f);
                }
            }
        }
示例#2
0
        /// <summary>
        /// This method is used to parse the given file.  Before calling this
        /// method the host member variable must be setup.  This method will
        /// create a data set, read the data set from the XML stored in the
        /// file, and then walk through the data set and create components
        /// stored within it.  The data set is stored in the persistedData
        /// member variable upon return.
        ///
        /// This method never throws exceptions.  It will set the successful
        /// ref parameter to false when there are catastrophic errors it can't
        /// resolve (like being unable to parse the XML).  All error exceptions
        /// are added to the errors array list, including minor errors.
        /// </summary>
        private string ReadFile(string fileName, ArrayList errors, out XmlDocument document)
        {
            string baseClass = null;

            // Anything unexpected is a fatal error.
            //
            try
            {
                // The main form and items in the component tray will be at the
                // same level, so we have to create a higher super-root in order
                // to construct our XmlDocument.

                MemoryStream s         = SaveLoadLayout.LoadFormDB(FormName);
                StreamReader sr        = new StreamReader(s);
                string       cleandown = sr.ReadToEnd();

                cleandown = "<DOCUMENT_ELEMENT>" + cleandown + "</DOCUMENT_ELEMENT>";

                XmlDocument doc = new XmlDocument();

                doc.LoadXml(cleandown);
                doc.Save("c:\\aa.xml");
                // Now, walk through the document's elements.
                //
                foreach (XmlNode node in doc.DocumentElement.ChildNodes)
                {
                    if (baseClass == null)
                    {
                        baseClass = node.Attributes["name"].Value;
                    }

                    if (node.Name.Equals("Object"))
                    {
                        ReadObject(node, errors);
                    }
                    else
                    {
                        errors.Add(string.Format("Node type {0} is not allowed here.", node.Name));
                    }
                }

                document = doc;
            }
            catch (Exception ex)
            {
                document = null;
                MessageBox.Show(ex.Message, "´íÎó");
            }
            return(baseClass);
        }