示例#1
0
        /// <summary>
        /// Gets the metadata for the given tag.
        /// </summary>
        public static SupportedTagMeta Get(MLNamespace ns, string tag)
        {
            SupportedTagMeta globalHandler;

            if (!ns.Tags.TryGetValue(tag, out globalHandler))
            {
                // Tag wasn't found in the given namespace.

                // Check if the namespace can help out by providing some other namespace:
                MLNamespace newNamespace = ns.GetNamespace(tag);

                if (newNamespace == null)
                {
                    // Use default:
                    globalHandler = ns.Default;
                }
                else
                {
                    ns = newNamespace;

                    // Try to get the handler:
                    if (!ns.Tags.TryGetValue(tag, out globalHandler))
                    {
                        // Use default:
                        globalHandler = ns.Default;
                    }
                }
            }

            return(globalHandler);
        }
示例#2
0
        /// <summary>Creates a new document and sets it to the given namespace.</summary>
        public Document createDocument(string namespaceUri, string qualifiedName, DocumentType doctype)
        {
            MLNamespace ns = null;

            // Get the namespace if there is one:
            if (!string.IsNullOrEmpty(namespaceUri))
            {
                ns = MLNamespaces.Get(namespaceUri);
            }

            // Create the document:
            Document document = (ns == null)? new Document() : ns.CreateDocument();

            // Add the doctype:
            if (doctype != null)
            {
                document.appendChild(doctype);
            }

            if (!string.IsNullOrEmpty(qualifiedName))
            {
                // Create the element:
                Element element = document.createElement(qualifiedName);

                if (element != null)
                {
                    document.appendChild(element);
                }
            }

            // Apply the base URI:
            document.basepath = _owner.basepath;

            return(document);
        }
示例#3
0
        /// <summary>Loads up the foreigners set.</summary>
        private void LoadForeigners()
        {
            Foreigners = new Dictionary <string, MLNamespace>();

            if (ForeignNames == null)
            {
                return;
            }

            string[] tags = ForeignNames.Split(',');

            for (int i = 0; i < tags.Length; i++)
            {
                // FQ with it's xmlns, e.g. 'svg:svg' or 'mml:math'
                string fullyQualifiedTag = tags[i];

                string[] tagParts = fullyQualifiedTag.Split(':');

                // Get the namespace from a (global only) prefix:
                MLNamespace ns = MLNamespaces.GetPrefix(tagParts[0]);

                // Add to set:
                Foreigners[tagParts[1]] = ns;
            }
        }
示例#4
0
        public XmlNamespace(string name, string prefix, string mime, Type docType)
        {
            Namespace = MLNamespaces.Get(name, prefix, mime);

            if (docType != null)
            {
                Namespace.DocumentType = docType;
            }
        }
示例#5
0
        /// <summary>Gets or creates a namespace.</summary>
        public static MLNamespace Get(string name, string prefix, string mime)
        {
            MLNamespace ns;

            if (!All.TryGetValue(name, out ns))
            {
                ns = new MLNamespace(name, prefix, mime);
                Prefixes[prefix] = ns;
                All[name]        = ns;
            }

            return(ns);
        }
示例#6
0
        /// <summary>Parses a complete document from the given string.</summary>
        public Dom.Document parseFromString(string text, string type)
        {
            // Try making the document by the given mime type:
            MLNamespace ns = MLNamespaces.GetByMime(type);

            // Create the document:
            Document document = (ns == null)? new Document() : ns.CreateDocument();

            // Parse the contents:
            if (text != null)
            {
                document.innerML = text;
            }

            return(document);
        }
示例#7
0
        public XmlNamespace(string name, string prefix, string mime, Type docType, string foreign)
        {
            Namespace = MLNamespaces.Get(name, prefix, mime);

            if (docType != null)
            {
                Namespace.DocumentType = docType;
            }

            if (foreign != null)
            {
                // Foreign elements (such as mathml's 'math' in html) are available.

                // Set:
                Namespace.ForeignNames = foreign;
            }
        }
示例#8
0
        /// <summary>Gets all available tag handlers.
        /// Note that interally lookups go through MLNamespace.Tags instead.</summary>
        public static Dictionary <string, Type> GetAll()
        {
            // Create:
            Dictionary <string, Type> set = new Dictionary <string, Type>();

            // For each namespace..
            foreach (KeyValuePair <string, MLNamespace> kvp in MLNamespaces.All)
            {
                MLNamespace ns = kvp.Value;

                // For each type..
                foreach (KeyValuePair <string, SupportedTagMeta> t in ns.Tags)
                {
                    set[ns.Prefix + ":" + t.Key] = t.Value.TagType;
                }
            }

            return(set);
        }
示例#9
0
        /// <summary>Creates a new element in this document with the given namespace.
        /// You'll need to parent it to something.</summary>
        public Element createElementNS(string namespaceName, string tag)
        {
            // Get the namespace by its URL:
            MLNamespace ns = MLNamespaces.Get(namespaceName);

            if (ns == null)
            {
                ns = Namespace;
            }

            // Create the element and call its startup methods:
            Element result = TagHandlers.Create(ns, tag) as Element;

            result.document_ = this;
            result.OnTagLoaded();
            result.OnChildrenLoaded();

            return(result);
        }
示例#10
0
        /// <summary>Attempts to find the tag with the given name.
        /// If it's not found, a default tag which is known to exist can be returned instead.
        /// The handler for the found tag is then instanced and the instance is returned.
        /// For example, tag "h1" with a default of "span".</summary>
        /// <param name="ns">The namespace the tag is in.</param>
        /// <param name="tag">The tag to look for.</param>
        /// <param name="defaultTag">If the given tag is not found, this is used instead.</param>
        /// <returns>An instance of the tag handler for the tag. Throws an error if tag or defaultTag are not found.</returns>
        public static Element Create(MLNamespace ns, string tag)
        {
            SupportedTagMeta globalHandler;

            if (!ns.Tags.TryGetValue(tag, out globalHandler))
            {
                // Tag wasn't found in the given namespace.

                // Check if the namespace can help out by providing some other namespace:
                MLNamespace newNamespace = ns.GetNamespace(tag);

                if (newNamespace == null)
                {
                    // Use default:
                    globalHandler = ns.Default;
                }
                else
                {
                    ns = newNamespace;

                    // Try to get the handler:
                    if (!ns.Tags.TryGetValue(tag, out globalHandler))
                    {
                        // Use default:
                        globalHandler = ns.Default;
                    }
                }
            }

            // Instance it now:
            Element result = Activator.CreateInstance(globalHandler.TagType) as Element;

            result.Namespace = ns;
            result.Tag       = tag;

            // Ok!
            return(result);
        }