ARTICLE

Mobile Fun with XML

Posted by Shivani Articles | XML May 24, 2001
Here is something really wonderful in Mobile field .This example is for authenticating the Mobile Users against his settings stored in XML file. This is really good where all the ease of XML is applied. Function open the XML file and particular node data validate it against user inputs and do the specified.
Reader Level:

Introduction

Here is something really wonderful in Mobile field .This example is for authenticating the Mobile Users against his settings stored in XML file. This is really good where all the ease of XML is applied. Function open the XML file and particular node data validate it against user inputs and do the specified.

The XML file shown below is a preformed XML file consisting of User Settings.

Users_data.xml

Here is the  mobile authentication code

Check it out

Source Code

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml" %>
<%@ Page Inherits="System.Mobile.UI.MobilePage" Language="C#" %>
<%@ Register TagPrefix="Mobile" Namespace="System.Mobile.UI" %>
<script runat="server" language="c#">
public string welcomeText;
public void Authenticate(String strFirst, String strLast, String realname)
{
if(strFirst==Name.Text && strLast==Password.Text)
{
welcomeText="Hi "+ realname +" u r successfully logged in";
ActiveForm = SecondForm;
}
}
public void SubmitBtn_Click(Object sender, EventArgs e)
{XmlDocument _doc =
new XmlDocument( );
_doc.Load("C:/Users_data.xml");
XmlNodeList _snames = _doc.GetElementsByTagName("UserID");
XmlNodeList _spasswords = _doc.GetElementsByTagName("Password");
XmlNodeList _susernames = _doc.GetElementsByTagName("UserName");
for ( int _i = 0; _i < _snames.Count; ++_i )
{
Authenticate( _snames[ _i].InnerText, _spasswords[ _i].InnerText,_susernames[_i].InnerText);
}
}
protected void SecondForm_OnActivate(Object sender, EventArgs e)
{
Greeting.Text = welcomeText;
}
</script>
<
Mobile:Form runat="server" id="FirstForm" BackColor="#336699" ForeColor="#ffffff">
<
Mobile:Label runat="server" FontName="Arial" FontSize="Large">U R Name?</Mobile:Label>
<
Mobile:TextBox runat="server" id="Name" ForeColor="#000000"/>
<
Mobile:Label runat="server" FontName="Arial" FontSize="Large">U R Password?</Mobile:Label>
<
Mobile:TextBox runat="server" Type="Password" id="Password" ForeColor="#000000" />
<
Mobile:Command runat="server" OnClick="SubmitBtn_Click" Text="LOGIN!" />
</
Mobile:Form>
<
Mobile:Form runat="server" id="SecondForm" OnActivate="SecondForm_OnActivate" FontName="Arial">
<
Mobile:Label runat="server" id="Greeting" FontSize="Large" />
<
Mobile:Label runat="server" id="Greeting1" FontSize="Large" />
<
Mobile:Link runat="server" FontSize="Small" Target="#FirstForm" Text="ReturnToStart"/>
</
Mobile:Form>

COMMENT USING

Trending up