locked
Reading Xml In WinRT RRS feed

  • Question

  • Hello ,

    How Can I Archive this in WinRT C# :

         XmlDocument myXml=new XmlDocument();

                myXml.Load("admin.xml”);            

                XmlNodeList userList = myXml.SelectNodes(“root/user”);

                foreach(XmlNode user in userList)

                {   

                    string userName = user[“username”].InnerText;

       }

    if (userName == textBox1.Text)

    {

               //Do Something Here

    }

    Looking Forward To Your Help 

    Hamid Wakili

    Sunday, September 8, 2013 6:40 PM

Answers

  • XDocument doc = XDocument.Parse(this.xml);//put your xml document here
                var rootNode = doc.Root;
                var nodes = rootNode.Nodes().ToList();
                foreach (XElement user in nodes)
                {
                    var username = user.Element("username").Value;
                }

    Monday, September 9, 2013 8:59 AM

All replies

  • Use XDocument class instead XmlDocument.


    Sunday, September 8, 2013 6:49 PM
  • Hey Oleg , Thanks For Your Reply

    The Problem that i am facing is not XmlDocument Over XDocument But Rather this :

     foreach(XmlNode user in userList)

                {   

                    string userName = user[“username”].InnerText;

       }

    But try to paste this code in your VS winRT App and Then see what error it brings. 

    Thank You

    Hamid Wakili

    Monday, September 9, 2013 7:32 AM
  • Hello.

    Please, provide XML example.

    Monday, September 9, 2013 7:56 AM
  • Here is the example : 

     XmlDocument myXml=new XmlDocument();

                myXml.Load("admin.xml”);            

                XmlNodeList userList = myXml.SelectNodes(“root/user”);

                foreach(XmlNode user in userList)

                {   

                    string userName = user[“username”].InnerText;

       }

    if (userName == textBox1.Text)

    {

               //Do Something Here

    }

    Monday, September 9, 2013 7:59 AM
  • No, I mean XML code that you need to parse :)

    Like:

    <xml>

     <userlist>

       <user/>

       <user/>

     </userlist>

    </xml>

    Can you provide it ?

    Monday, September 9, 2013 8:24 AM
  • <root>
    <user>
    <id>1</id>
    <username>hamid</username>
    <password>1234</password>


    </user>
    </root>
    Monday, September 9, 2013 8:26 AM
  • XDocument doc = XDocument.Parse(this.xml);//put your xml document here
                var rootNode = doc.Root;
                var nodes = rootNode.Nodes().ToList();
                foreach (XElement user in nodes)
                {
                    var username = user.Element("username").Value;
                }

    Monday, September 9, 2013 8:59 AM
  • Thank You A lot Oleg , It Works :)

    Hamid Wakili

    Monday, September 9, 2013 9:20 AM