Example #1
0
        internal static NodeStats CountNode(Dictionary <string, NodeStats> ht, string name)
        {
            NodeStats es = null;

            if (!ht.TryGetValue(name, out es))
            {
                ht[name] = es = new NodeStats(name);
            }
            else
            {
                es.Count++;
            }
            return(es);
        }
Example #2
0
        internal static NodeStats CountNode(Hashtable ht, string name)
        {
            NodeStats es = (NodeStats)ht[name];

            if (es == null)
            {
                ht[name] = es = new NodeStats(name);
            }
            else
            {
                es.Count++;
            }
            return(es);
        }
Example #3
0
        /// <summary>
        /// Add stats from the given xml reader to the current XmlStats.
        /// </summary>
        public void Process(XmlTextReader r)
        {
            if (r == null)
            {
                return;
            }

            r.WhitespaceHandling = this._whiteSpace;

            Stack     elementStack   = new Stack();
            NodeStats currentElement = null;

            while (r.Read())
            {
                switch (r.NodeType)
                {
                case XmlNodeType.CDATA:
                case XmlNodeType.Text:
                {
                    long len = r.Value.Length;
                    currentElement.Chars += len;
                    this._elemChars      += len;
                    break;
                }

                case XmlNodeType.Element:
                    this._elemCount++;

                    if (r.IsEmptyElement)
                    {
                        this._emptyCount++;
                    }

                    NodeStats es = CountNode(this._elements, r.Name);
                    elementStack.Push(es);
                    currentElement = es;

                    while (r.MoveToNextAttribute())
                    {
                        if (es.Attrs == null)
                        {
                            es.Attrs = new Dictionary <string, NodeStats>();
                        }

                        var attrs = es.Attrs;

                        this._attrCount++;

                        // create a name that makes attributes unique to their parent elements
                        NodeStats ns = CountNode(attrs, r.Name);
                        string    s  = r.Value;
                        if (s != null)
                        {
                            long len = r.Value.Length;
                            ns.Chars        += len;
                            this._attrChars += len;
                        }
                    }
                    break;

                case XmlNodeType.EndElement:
                    currentElement = (NodeStats)elementStack.Pop();
                    break;

                case XmlNodeType.Entity:
                    break;

                case XmlNodeType.EndEntity:
                    break;

                case XmlNodeType.EntityReference:
                    // if you want entity references expanded then use the XmlValidatingReader.
                    // or perhaps we should report a list of them!
                    break;

                case XmlNodeType.ProcessingInstruction:
                    this._piCount++;
                    this._piChars += r.Value.Length;
                    break;

                case XmlNodeType.Comment:
                    this._commentCount++;
                    this._commentChars += r.Value.Length;
                    break;

                case XmlNodeType.SignificantWhitespace:
                    this._whiteSChars += r.Value.Length;
                    break;

                case XmlNodeType.Whitespace:
                    this._whiteChars += r.Value.Length;
                    break;

                case XmlNodeType.None:
                    break;

                case XmlNodeType.Notation:
                    break;

                case XmlNodeType.XmlDeclaration:
                    break;

                case XmlNodeType.Document:
                    break;

                case XmlNodeType.DocumentFragment:
                    break;

                case XmlNodeType.DocumentType:
                    break;
                }
            }
            r.Close();
        }