Hello,

When I open my app an XML doc is created with several elements giving to each of them the value 0. After the XML is created I want that several labels on the form to change their text to spcific elements' values (in this case 0). Is there any way to that? I'm using labels because they fit my needs... I don't know if there is another control that can be used better.

private void createXMLdoc()
        {
            XmlDocument mainDoc = new XmlDocument();
            XmlDeclaration mainDocDec = mainDoc.CreateXmlDeclaration("1.0", null, null);
            mainDoc.AppendChild(mainDocDec);
            XmlElement root = mainDoc.CreateElement("AllTimeElements");
            mainDoc.AppendChild(root);

            XmlElement X1 = mainDoc.CreateElement("X1");
            X1.InnerText = "0";
            root.AppendChild(X1);
            XmlElement X2= mainDoc.CreateElement("X2");
            X2.InnerText = "0";
            root.AppendChild(X2);            
            XmlElement X3= mainDoc.CreateElement("X3");
            X3.InnerText = "0";
            root.AppendChild(X3);
            XmlElement X4= mainDoc.CreateElement("X4");
            X4.InnerText = "0";
            root.AppendChild(X4);
            XmlElement X5= mainDoc.CreateElement("X5");
            X5.InnerText = "0";
            root.AppendChild(X5);
            XmlElement X6= mainDoc.CreateElement("X6");
            X6.InnerText = "0";
            root.AppendChild(X6);
            XmlElement X7= mainDoc.CreateElement("X7");
            X7.InnerText = "0";
            root.AppendChild(X7);
            XmlElement X8= mainDoc.CreateElement("X8");
            X8.InnerText = "0";
            root.AppendChild(X8);
            XmlElement X9= mainDoc.CreateElement("X9");
            X9.InnerText = "0";
            root.AppendChild(X9);
            XmlElement X10= mainDoc.CreateElement("X10");
            X10.InnerText = "0";
            root.AppendChild(X10);
            XmlElement X11= mainDoc.CreateElement("X11");
            X11.InnerText = "0";
            root.AppendChild(X11);
            XmlElement X12= mainDoc.CreateElement("X12");
            X12.InnerText = "0";
            root.AppendChild(X12);
            XmlElement X13= mainDoc.CreateElement("X13");
            X13.InnerText = "0";
            root.AppendChild(X13);

            mainDoc.Save(@"C:\\Windows\Temp\SessionsTotal.xml");
         }

        private void displayXMLdoc()
        {
            XmlDocument mainDisplay = new XmlDocument();
            mainDisplay.Load(@"C:\\Windows\Temp\SessionsTotal.xml");

            //here goes code to display the elements' values

        }

i think my basic xml retrieving data tutorial help you

1st make studentdb.xml file and copy paste
above code

<?xml version="1.0" encoding="utf-8"?>
<students>
<student>
<roll>01</roll>
<name>hassan</name>
</student>
<student>
<roll>02</roll>
<name>mani</name>
</student>
<student>
<roll>03</roll>
<name>waqas</name>
</student>
<junierstudent>
<name>AHMAD</name>
<roll>200</roll>
</junierstudent>
</students>

then retrive data from c# with following codes

XmlDocument doc = new XmlDocument();
doc.Load("studentdb.xml");


XmlElement elem=doc.DocumentElement;

// MessageBox.Show(elem.FirstChild.NextSibling.InnerText); //2nd record mani
//MessageBox.Show(elem.FirstChild.InnerText); //1st record hassan
//MessageBox.Show(elem.FirstChild.FirstChild.InnerText); //1st record hassan 1st data name

XmlNodeList nodelist = elem.GetElementsByTagName("name");


for (int i = 0; i < nodelist.Count;i++ )

listBox1.Items.Add(nodelist.Item(i).InnerText);

nevermind... i got it to work

XmlTextReader reader = new XmlTextReader(@"C:\\Windows\Temp\SessionsTotal.xml");
            XmlNodeType type;

            while (reader.Read())
            {
                type = reader.NodeType;

                if (type == XmlNodeType.Element)
                {
                    if (reader.Name == "X1")
                    {
                        reader.Read();
                        x1Text.Text = reader.Value;
                    }

                    if (reader.Name == "X2")
                    {
                        reader.Read();
                        x2Text.Text = reader.Value;
                    }
This question has already been answered. Start a new discussion instead.