コード例 #1
0
        public static string CompressXML(XmlDocument doc, XmlElement el)
        {
            Hashtable hashtable  = new Hashtable();
            Hashtable hashtable2 = new Hashtable();
            int       num        = 0;

            SvgFactory.RecCompXML(hashtable, hashtable2, doc, el, ref num);
            foreach (DictionaryEntry dictionaryEntry in hashtable2)
            {
                string text = (string)dictionaryEntry.Key;
                SvgFactory.EntitySingleton entitySingleton = (SvgFactory.EntitySingleton)dictionaryEntry.Value;
                entitySingleton.Element.RemoveAttribute(entitySingleton.AttributeName);
                XmlAttribute xmlAttribute = doc.CreateAttribute(entitySingleton.AttributeName);
                xmlAttribute.Value = text;
                entitySingleton.Element.SetAttributeNode(xmlAttribute);
                hashtable.Remove(text);
            }
            StringBuilder stringBuilder = new StringBuilder();

            if (hashtable.Count > 0)
            {
                stringBuilder.Append("\n");
                foreach (string text2 in hashtable.Keys)
                {
                    stringBuilder.Append("<!ENTITY ");
                    stringBuilder.Append(hashtable[text2]);
                    stringBuilder.Append(" '");
                    stringBuilder.Append(text2.Replace("%", "&#37;"));
                    stringBuilder.Append("'>");
                }
                stringBuilder.Append("\n");
            }
            return(stringBuilder.ToString());
        }
コード例 #2
0
        private static void RecCompXML(Hashtable entities, Hashtable singletons, XmlDocument doc, XmlElement el, ref int idx)
        {
            ArrayList arrayList = new ArrayList();

            foreach (XmlAttribute xmlAttribute in el.Attributes)
            {
                arrayList.Add(xmlAttribute.Name);
            }
            foreach (string text in arrayList)
            {
                string value = el.Attributes[text].Value;
                if (value.Length > 30)
                {
                    string text2;
                    if (entities[value] == null)
                    {
                        idx++;
                        text2             = "E" + idx.ToString();
                        entities[value]   = text2;
                        singletons[value] = new SvgFactory.EntitySingleton
                        {
                            Element       = el,
                            AttributeName = text
                        };
                    }
                    else
                    {
                        text2 = (string)entities[value];
                        singletons.Remove(value);
                    }
                    XmlAttribute xmlAttribute2 = doc.CreateAttribute(text);
                    xmlAttribute2.AppendChild(doc.CreateEntityReference(text2));
                    el.SetAttributeNode(xmlAttribute2);
                }
            }
            foreach (XmlNode xmlNode in el.ChildNodes)
            {
                if (xmlNode.GetType() == typeof(XmlElement))
                {
                    SvgFactory.RecCompXML(entities, singletons, doc, (XmlElement)xmlNode, ref idx);
                }
            }
        }