Quantcast
Viewing all articles
Browse latest Browse all 12583

Getting "out of memory exception" when populating treeview from large xml data.

Hi All,

I am facing "Out of Memory" issue when I am populating TreeView hierarchy using XML. Our XML structure is very complex and it is not in fix format. There are multiple level of child nodes. I am using recursion to iterate XML and populate TreeView structure. I tried to call GC.   to clear memory but still it is throwing same error.

I am using C# of .NET framework 3.5 for development.

I will appreciate if you can help me to find solution for this.

I'm providing the Code, Which I'm using for populating the treeview, below

        private void addTreeNode(XmlNode xmlNode, TreeNode treeNode)
        {
            string attribute = "";

            treeView1.ImageList = imageList1;
            treeViewResponse.ImageList = imageList1;
            XmlNode xNode;
            TreeNode tNode;
            XmlNodeList xNodeList;
            foo.MoveToFollowing(XPathNodeType.Element);
            namespaces1 = foo.GetNamespacesInScope(XmlNamespaceScope.All);
            if (xmlNode.HasChildNodes)
            {

                treeNode.ImageIndex = 0;
                treeNode.SelectedImageIndex = 0;
                xNodeList = xmlNode.ChildNodes;
                for (int x = 0; x <= xNodeList.Count - 1; x++)
                {
                    xNode = xmlNode.ChildNodes[x];
                    treeNode.Nodes.Add(new TreeNode(xNode.Name));
                    tNode = treeNode.Nodes[x];
                    //treeNode.Nodes[x].ImageIndex = -1;
                    addTreeNode(xNode, tNode);
                }
            }
            else
            {
                treeNode.ImageIndex = 1;
                treeNode.NodeFont = new Font("Arial", 8, FontStyle.Bold);
                treeNode.SelectedImageIndex = 1;
                treeNode.Text = xmlNode.OuterXml.Trim();
            }
        }

Thanks in advance.

Regards,

Rajeev



Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>