Beispiel #1
0
        public void ParseEntities(string path, string fileName)
        {
            this.names_ = new Hashtable(0x834, 0.5f);
            try
            {
                XmlDocument doc = new XmlDocument();

                Stream stream = ResourceLoader.GetStream(path, fileName);
                if (stream == null)
                {
                    return;
                }
                doc.Load(stream);
                stream.Close();


                XmlNode n = doc.DocumentElement;
                if (n.HasChildNodes)
                {
                    for (int i = 0; i < n.ChildNodes.Count; i++)
                    {
                        if (n.ChildNodes[i].Name == "MathML_Entities")
                        {
                            n = n.ChildNodes[i];
                            int count = n.ChildNodes.Count;
                            for (int j = 0; j < count; j++)
                            {
                                try
                                {
                                    XmlNode xmlNode = n.ChildNodes[j];
                                    if (xmlNode != null)
                                    {
                                        EntityInfo entityInfo = this.ParseEntity(j, xmlNode);

                                        try
                                        {
                                            if (!this.names_.Contains(entityInfo.Name))
                                            {
                                                this.names_.Add(entityInfo.Name, entityInfo);
                                            }
                                        }
                                        catch
                                        {
                                        }
                                        try
                                        {
                                            if (!this.codes_.Contains(entityInfo.Code))
                                            {
                                                this.codes_.Add(entityInfo.Code, entityInfo);
                                            }
                                        }
                                        catch
                                        {
                                        }
                                        this.list_.Add(entityInfo);
                                    }
                                }
                                catch
                                {
                                }
                            }
                        }
                    }
                }
                try
                {
                    doc.LoadXml("<root/>");
                    doc = null;
                }
                catch
                {
                }
            }
            catch
            {
            }
        }
Beispiel #2
0
        private EntityInfo ParseEntity(int index, XmlNode node)
        {
            EntityInfo info = null;

            try
            {
                XmlNode nameNode         = node.Attributes.GetNamedItem("name");
                XmlNode uniNode          = node.Attributes.GetNamedItem("unicode");
                XmlNode viNode           = node.Attributes.GetNamedItem("visible");
                XmlNode uniAlias         = node.Attributes.GetNamedItem("unicodeAlias");
                XmlNode ffNode           = node.Attributes.GetNamedItem("font_family");
                XmlNode descNode         = node.Attributes.GetNamedItem("description");
                XmlNode descFont         = node.Attributes.GetNamedItem("description_font");
                string  name             = "";
                string  code             = "";
                string  codeAlias        = "";
                string  description      = "";
                string  description_font = "";
                bool    visible          = true;
                if (nameNode != null)
                {
                    name = nameNode.Value;
                }
                if (uniNode != null)
                {
                    code = uniNode.Value;
                }
                if (viNode != null)
                {
                    visible = Convert.ToBoolean(viNode.Value);
                }
                if (uniAlias != null)
                {
                    codeAlias = uniAlias.Value;
                }
                if (descNode != null)
                {
                    description = descNode.Value;
                }
                if (descFont != null)
                {
                    description_font = descFont.Value;
                }
                info = new EntityInfo(index, name, code, codeAlias, description, description_font, visible);
                try
                {
                    info.Category = this.GetCategory(info.Code);
                }
                catch
                {
                }
                if (ffNode != null)
                {
                    string familyList = ffNode.Value;
                    if (familyList.Length <= 0)
                    {
                        return(info);
                    }
                    this.ParseFamilyList(info, familyList);
                }
            }
            catch
            {
            }
            return(info);
        }
Beispiel #3
0
 public bool ReplaceEntities(string sSource, ref string outXml)
 {
     try
     {
         string s         = sSource;
         int    count     = 0;
         int    index     = 0;
         int    semiIndex = 0;
         while ((index != -1) && (index < s.Length))
         {
             index = s.IndexOf("&", index);
             if ((index != -1) && (index < s.Length))
             {
                 semiIndex = s.IndexOf(";", index);
                 if ((((semiIndex < s.Length) && ((semiIndex - index) > 2)) && (((semiIndex - index) < 100) && (s[index + 1] == '#'))) && (s[index + 2] == 'x'))
                 {
                     int p = index + 1;
                     int e = semiIndex;
                     if (((e > p) && ((e - p) > 1)) && ((e < s.Length) && (p < s.Length)))
                     {
                         try
                         {
                             string unicode = s.Substring(p + 2, (e - p) - 2);
                             unicode = unicode.PadLeft(5, '0');
                             if (!this.InTag(s, p))
                             {
                                 if (unicode.Length > 0)
                                 {
                                     EntityInfo entityInfo = this.mapper_.ItemFromHex(unicode);
                                     if (entityInfo != null)
                                     {
                                         if (entityInfo.Name.Length > 0)
                                         {
                                             s = s.Remove(p, e - p);
                                             s = s.Insert(p, entityInfo.Name);
                                         }
                                         else
                                         {
                                             s = s.Remove(p, e - p);
                                             s = s.Insert(p, "quest");
                                         }
                                         count++;
                                     }
                                     else
                                     {
                                         s = s.Remove(p, e - p);
                                         s = s.Insert(p, "quest");
                                         count++;
                                     }
                                 }
                                 else
                                 {
                                     s = s.Remove(p, e - p);
                                     s = s.Insert(p, "quest");
                                     count++;
                                 }
                             }
                         }
                         catch
                         {
                         }
                     }
                 }
                 index++;
             }
         }
         if (count > 0)
         {
             outXml = s;
             return(true);
         }
     }
     catch
     {
     }
     return(false);
 }