[jdev] .Net XML Dom Stuff

Jonathan Dickinson jonathanD at k2.com
Fri Jun 6 01:53:46 CDT 2008


Hi All,

For those of you who are interested, I have found a work-around for the classical DOM issues and streams in .Net (large DOM after a busy client). The solution is obvious if you think about it and I have no idea why I didn't come up with it before.

Simply delete the elements from the DOM as you no longer need them! Here is some code demonstrating the concept:

void IXmlNotificationTarget.XmlElementStarted(XmlElement element)
        {
            depth++;

            object o = Deserialize(element);

            // Root.
            if (depth == 1)
            {
                if (o != null)
                    target.StanzaOpened(o, depth);
            }
            // Stanza.
            else if (depth == 2)
            {
                if (o != null)
                    target.StanzaOpened(o, depth);
            }
        }

        void IXmlNotificationTarget.XmlElementEnded(XmlElement element)
        {
            object o = Deserialize(element);

            // Root.
            if (depth == 1)
            {
                if (o != null)
                    target.StanzaClosed(o, depth);
            }
            // Stanza.
            else if (depth == 2)
            {
                if (o != null)
                    target.StanzaClosed(o, depth);

                // Remove self.
                element.ParentNode.RemoveChild(element);
                // Completely destroy.
                element.RemoveAll();
            }

            depth--;
        }

HTH

Jonathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.jabber.org/pipermail/jdev/attachments/20080606/8672a882/attachment-0002.htm>


More information about the JDev mailing list