0

我想阅读我的 xml,如果文本框中的文本与 xml 中的标签相同,我希望它导航到其他页面。

我的代码是:

     StorageFolder storageFolder = Package.Current.InstalledLocation;
        StorageFile storageFile = await storageFolder.GetFileAsync("Registeduser.xml");

        string xml = await FileIO.ReadTextAsync(storageFile, Windows.Storage.Streams.UnicodeEncoding.Utf8);
        var doc = XDocument.Parse(xml);

        StorageFolder pastaxml = Package.Current.InstalledLocation;
        pastaxml = await pastaxml.GetFolderAsync("users\\1101046102\\xml\\");
        StorageFile login = await pastaxml.GetFileAsync("info.xml");

        string xmllogin = await FileIO.ReadTextAsync(login, Windows.Storage.Streams.UnicodeEncoding.Utf8);

        var xdoc = XDocument.Parse(xmllogin);

        var rootemail = xdoc.Root;

        var rootNode = doc.Root;
        foreach (var child in rootNode.Descendants("user"))
        {
            //Login is a class
            var objLogin = new Login
            {
                id = child.Element("id").Value,
                Email=child.Element("email").Value
            };
        }
        foreach (var logemail in rootemail.Descendants("info"))
        {
            //Info is a class
            var email = new Info
            {
               Email = logemail.Element("email").Value
            };
            Info info = new Info();

            if (txtemail.Text == info.Email.ToString())
            {
                this.Frame.Navigate(typeof(DashBoard));
            }
            else
            {
                MessageBox("Email ou password incorreta");
            }
        }

xml是:

    <info>
        <id>1101046102</id>
       <email>email@hotmail.com</email>
    </info>

和:

    <?xml version="1.0" encoding="utf-8" ?>
   <registeredUser>
      <user>
        <id>1101046102</id>
        <email>email@hotmail.com</email>
      </user>
   </registeredUser>

我想要的只是将注册用户.xml 中的电子邮件与 info.xml 中的电子邮件进行比较。当我调试程序并单击转到下一页时,程序不执行任何操作。我做错了什么?

4

1 回答 1

0

我想要的只是将注册用户.xml 中的电子邮件与 info.xml 中的电子邮件进行比较

bool isEqual = doc.Descendants("email").First().Value == 
               xdoc.Descendants("email").First().Value;
于 2013-09-09T17:58:47.993 回答