Ejemplo n.º 1
0
        /// <summary>
        /// Open an existing xml file.  This must be called before any other methods can be used.
        /// </summary>
        /// <param name="fileName">The full path to the xml file to open.
        /// If this is "", then a new empty xml document is created.</param>
        /// <returns>A name for the document or "FAILED".</returns>
        public static Primitive Open(Primitive fileName)
        {
            try
            {
                Type ShapesType = typeof(Shapes);
                MethodInfo method = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                string docName = method.Invoke(null, new object[] { "XMLDoc" }).ToString();

                if (System.IO.File.Exists(fileName))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(fileName);
                    xmlDoc = new XmlDoc(doc);
                    documents[docName] = xmlDoc;
                    return docName;
                }
                else if (fileName == "")
                {
                    XmlDocument doc = new XmlDocument();
                    doc.AppendChild(doc.CreateElement("root"));
                    xmlDoc = new XmlDoc(doc);
                    documents[docName] = xmlDoc;
                    XmlDeclaration xmldecl = xmlDoc.doc.CreateXmlDeclaration("1.0", "UTF-8", null);
                    xmlDoc.doc.InsertBefore(xmldecl, xmlDoc.doc.DocumentElement);
                    return docName;
                }
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
            }
            return "FAILED";
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Performs the inverse function of ToArray method, create an xml document from an array definition.
        /// </summary>
        /// <param name="array">A Small Basic array with the correct format.</param>
        /// <returns>A name for the document or "FAILED".</returns>
        public static Primitive FromArray(Primitive array)
        {
            Type ShapesType = typeof(Shapes);
            MethodInfo method = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
            string docName = method.Invoke(null, new object[] { "XMLDoc" }).ToString();

            try
            {
                XmlDocument doc = new XmlDocument();
                xmlDoc = new XmlDoc(doc);
                xmlDoc.node = xmlDoc.doc.DocumentElement;
                fromArray(array);
                documents[docName] = xmlDoc;
                return docName;
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
            }
            return "FAILED";
        }