locked
Can Anyone tell me what is wrong here?

    Question

  • hai guys i want to read an xml line i wrote this code but its wrong i get stuck at nodes.

    this is what is inside the xml file i called it "login.xml"

    <?xml version="1.0" encoding="UTF-8"?>

    -<informacao xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <Data1>master</Data1>

    <Data2>master</Data2>

    </informacao>

        private void button1_Click(object sender, EventArgs e)
            {

                XmlDocument doc = new XmlDocument();
                doc.LoadXml("login.xml");

                XmlNodeList nodes = doc.SelectNodes("data1");
                if (textBox1.Text = nodes) ; <--- here instead of nodes. how do i say that if the textbox1.text is equal to the text that is on data1 example <Data1>master</Data1> in this case "master"

                this.Hide();
                Form1 f1 = new Form1();
                f1.Show();
            }

    plis i would apreciate some codes answering my question ty:D
    • Edited by tjunior Sunday, March 16, 2014 9:26 PM
    Sunday, March 16, 2014 9:24 PM

All replies

  • Hi,

    If you XML file like below:

    <?xml version="1.0" encoding="UTF-8"?>
    
    <informacao xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    
     <Data1>master</Data1>
    
     <Data2>master</Data2>
    
     </informacao> 

    You can get Data1 value use these codes:

    private void Button_Click(object sender, RoutedEventArgs e)
            {
                string peopleXMLPath = Path.Combine(Package.Current.InstalledLocation.Path, "Assets/XMLFile1.xml");
                XDocument loadedData = XDocument.Load(peopleXMLPath);
             var data = from query in loadedData.Descendants("informacao")
                           select new informacao
                           {
                               Data1 = (string)query.Element("Data1"),
                               Data2 = (string)query.Element("Data2")
                              
                           };
    
             informacao firstelement= data.First<informacao>();
             string data1 = firstelement.Data1;
    
            }

    Please refer to the link below:

    http://www.geekchamp.com/articles/how-to-read-xml-files-in-windows-8---winrt

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, March 17, 2014 4:05 AM
  • thanks man for the code but i still have a problm here

     private void button1_Click(object sender, EventArgs e)
            {           

                string peopleXMLPath = Path.Combine("login.xml");
                XDocument loadedData = XDocument.Load(peopleXMLPath);
                var data = from query in loadedData.Descendants("informacao")
                           select new informacao
                           {
                               Data1 = (string)query.Element("Data1"),
                               Data2 = (string)query.Element("Data2")

                           };
                informacao firstelement = data.First<informacao>();
                string data1 = firstelement.Data1;

                if (textBox1.Text == firstelement.Data1 || textBox2.Text== firstelement.Data2) ;

                    this.Hide();
                    Form1 f1 = new Form1();
                    f1.Show();<------- its saying that only assigment,call,increment,await and new object expressions can be used as statement

                else   <--- is saying that is a invalid expression term
                MessageBox.Show("login or password is not correct","Login",MessageBoxButtons.OK);

    }

    plis i would apreciate your help thanks!


    • Edited by tjunior Monday, March 17, 2014 2:26 PM
    Monday, March 17, 2014 2:12 PM
  • Hi,

    Do you create a windows store app or windows Form app. About your code, seem your app is windows form application. I recommend you should go to the windows form forum to post your thread:

    http://social.msdn.microsoft.com/Forums/windows/en-US/home?forum=winforms

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, March 19, 2014 6:06 AM