Xml node reading for each loop Xml node reading for each loop xml xml

Xml node reading for each loop


You are repeatedly assigning node with the same element from testDoc. It is not clear what test.account is (perhaps a mistype for test.actual)?

no is the variable which will iterate the contents of nodeList - I imagine you intended to use that.

EDIT following edit of OPNow you've shown us what nodeList is, I suspect you want to do something like this instead :

XmlNodeList nodeList = testDoc.SelectNodes("/details/row/var[@name='account']"); foreach (XmlNode no in nodeList) {       test.actual = no.Attributes["value"].Value;   ...


        XmlDocument doc = new XmlDocument();        doc.Load("d:\\test.xml");        XmlNodeList node = doc.GetElementsByTagName("w:r");        foreach (XmlNode xn in node)        {            try            {                if (xn["w:t"].InnerText != null)                {                    if (xn["w:t"].InnerText == "#")                    {                        string placeHolder = xn["w:t"].InnerText;                        foreach (XmlNode a in node)                        {                             if (a["w:t"].InnerText != "#")                            {                                string placeHolder1 = a["w:t"].InnerText;                            }                        }                     }                }            }            catch (Exception e)            {                Console.Write(e);            }        } 


Here is the sample for parent node value to get information of the child nodes.here i am using the ReportItems ParentNode and Print only image child nodes.

        xmldoc.Load(rdlFile);        StringBuilder sb=new StringBuilder();        XmlNode node = xmldoc.GetElementsByTagName("ReportItems")[0];        XmlNodeList list = node.ChildNodes;        atributes=new string[node.ChildNodes.Count];        int  l = 0;        for (int j = 0; j < node.ChildNodes.Count; j++)        {            if (list[j].Name == "Image")            {                XmlAttributeCollection att = list[j].Attributes;                atributes[l] = att[0].Value.ToUpper();            }            l++;        }        for (int i = 0; i < node.ChildNodes.Count; i++)        {            if (searchText.Text.ToUpper() == atributes[i])            {                XmlNodeList lastlist = node.ChildNodes;                XmlNodeList endlist = lastlist[i].ChildNodes;                for (int k = 0; k < endlist.Count; k++)                {                    sb.Append(endlist[k].Name+" - "+ endlist[k].InnerText);                    sb.Append("\n"+"\n");                }            }        }

let me know if you have doubt..