Exemple #1
0
        /// <summary>
        /// Used by CompressXML
        /// </summary>
        /// <param name="entities">Map of attribute to entity name</param>
        /// <param name="singletons">Output: List of single use attributes to 'uncompress'</param>
        /// <param name="doc"></param>
        /// <param name="el"></param>
        /// <param name="idx">Number that is incremented to provide new entity names</param>
        private static void RecCompXML(Hashtable entities, Hashtable singletons, XmlDocument doc, XmlElement el, ref int idx)
        {
            var keys = new ArrayList();

            foreach (XmlAttribute att in el.Attributes)
            {
                keys.Add(att.Name);
            }

            foreach (string s in keys)
            {
                var val = el.Attributes[s].Value;

                if (val.Length > 30)
                {
                    string entname;

                    if (entities[val] == null)
                    {
                        idx++;
                        entname       = "E" + idx.ToString();
                        entities[val] = entname;

                        singletons[val] = new EntitySingleton()
                        {
                            Element = el, AttributeName = s
                        };
                    }
                    else
                    {
                        entname = (string)entities[val];

                        singletons.Remove(val);
                    }

                    var attr = doc.CreateAttribute(s);
                    attr.AppendChild(doc.CreateEntityReference(entname));
                    el.SetAttributeNode(attr);
                }
            }

            foreach (XmlNode ch in el.ChildNodes)
            {
                if (ch.GetType() == typeof(XmlElement))
                {
                    RecCompXML(entities, singletons, doc, (XmlElement)ch, ref idx);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Used by CompressXML
        /// </summary>
        /// <param name="counts">Map of attribute to number of occurrences -- could be used to improve algorithm</param>
        /// <param name="entities">Map of attribute to entity name</param>
        /// <param name="doc"></param>
        /// <param name="el"></param>
        /// <param name="idx">Number that is incremented to provide new entity names</param>
        private static void RecCompXML(Hashtable entities, Hashtable singletons, XmlDocument doc, XmlElement el, ref int idx)
        {
            ArrayList keys = new ArrayList();

            foreach(XmlAttribute att in el.Attributes)
            {
                keys.Add(att.Name);
            }

            foreach(string s in keys)
            {
                string val = el.Attributes[s].Value;

                if (val.Length > 30)
                {
                    string entname;

                    if(entities[val] == null)
                    {
                        idx += 1;
                        entname = "E"+idx.ToString();
                        entities[val] = entname;

                        singletons[val] = new EntitySingleton() { Element = el, AttributeName = s };
                    }
                    else
                    {
                        entname = (string)entities[val];

                        singletons.Remove(val);
                    }

                    XmlAttribute attr = doc.CreateAttribute(s);
                    attr.AppendChild(doc.CreateEntityReference(entname));
                    el.SetAttributeNode(attr);
                }

            }

            foreach(XmlNode ch in el.ChildNodes)
            {
                if (ch.GetType() == typeof(XmlElement))
                    RecCompXML(entities, singletons, doc, (XmlElement)ch, ref idx);
            }
        }