|
|
|
|
|
|
|
Page Views :
|
2117
|
|
Downloads :
|
0
|
|
Rating :
|
Rate it
|
|
Level :
|
Intermediate
|
|
Description
In this article, I would like to discuss about "Weather Update" on your mobile phone. When we get up in the early morning , everyone curious to know about the weather . I hope that it would be very useful to everyone to make a plan for a day.
In this Example, I am just using XML file as a dynamic data source, for reading data from XML file I am just using "XmlTextReader" class.
The CLR (Common Language Runtime) which specifies the common type libraries to be used by all programming languages on the .NET Platform has full support for XML. The special Namespace reserved for XML is "System.Xml". This namespace has many types to read, write and manipulate XML data. Since the CLR natively supports XML, there is guaranteed ease of use and support of XML in all the languages that will run on .NET platform..
The XmlTextReader class has several constructors that allow for various situations, such as reading from an existing stream or from a URL. Most often, perhaps, you will want to read XML from a file, and there's a constructor for this as well.
XmlTextReader (a class derived from XmlReader) supports reading XML documents from a text-based stream XmlReader and XMLWriter are the two abstract classes at the core of .NET Framework XML classes.
XmlTextReader, contained in the .NET Framework's System.XML namespace, reads data from an XML file quickly without placing high demands on system resources. XmlTextReader provides fast, forward-only, non-cached access to XML data. (Forward-only means you can read the XML file from beginning to end but cannot move backwards in the file.)
XmlValidatingReader is used in conjunction with the XmlTextReader class to provide the capability for DTD, XDR, and XSD schema validation.
When using the NodeType property, it is important to understand how nodes relate to XML elements.
For example, In XML file, <city>auckland</city>
The XmltextReader class are the following members for reading the data from XML file
- The <city> tag is read as a type XmlNodeType.Element node. The name of the element, "city," is available in the XmlTextReader's Name property.
- The "auckland" text data is read as a type XmlNodeType.Text node. The data "auckland" is available in the XmlTextReader's Value property.
- The </city> tag is read as a type XmlNodeType.EndElement node. Again, the name of the element, "city," is available in the XmlTextReader's Name property.
Just have a look at the dynamic XML Source file
XML FILE:
<?xml version="1.0" ?> <weatherinfo> <auckland> <updated>31/01/2002 09:00</updated> <city>auckland</city> <forecast>Fine. A mostly sunny day with light winds</forecast> <min>24</min> <max>25</max> </auckland> <chennai> <updated>31/01/2002 09:00</updated> <city>chennai</city> <forecast>Fine.</forecast> <min>35</min> <max>38</max> </chennai> <hongkong> <updated>31/01/2002 09:00</updated> <city>hongkong</city> <forecast>Early rain</forecast> <min>23</min> <max>25</max> </hongkong> <mumbai> <updated>31/01/2002 09:00</updated> <city>mumbai</city> <forecast>Sunny day</forecast> <min>29</min> <max>35</max> </mumbai> <malaysia> <updated>31/01/2002 09:00</updated> <city>malaysia</city> <forecast>raining</forecast> <min>24</min> <max>25</max> </malaysia> <newdelhi> <updated>31/01/2002 09:00</updated> <city>newdelhi</city> <forecast>Fine</forecast> <min>30</min> <max>35</max> </newdelhi> <newyork> <updated>31/01/2002 09:00</updated> <city>newyork</city> <forecast>Very Cold</forecast> <min>24</min> <max>25</max> </newyork> <singapore> <updated>31/01/2002 09:00</updated> <city>singapore</city> <forecast>rain day</forecast> <min>31</min> <max>35</max> </singapore> <tokyo> <updated>31/01/2002 09:00</updated> <city>tokyo</city> <forecast>sunny day </forecast> <min>22</min> <max>25</max> </tokyo> <sydney> <updated>31/01/2002 09:00</updated> <city>sydney</city> <forecast>Fine</forecast> <min>21</min> <max>25</max> </sydney> <washington> <updated>31/01/2002 09:00</updated> <city>washington</city> <forecast>Fine.very cold</forecast> <min>23</min> <max>25</max> </washington> </weatherinfo>
//XML File End
Source Code
//Source Code Starts <%@ Page Inherits=" System.Web.UI.MobileControls.MobilePage"Language="cs" %> <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %> <% @Import Namespace="System.Xml"%> <script runat="server"> public void List_ClickEventHandler(Object source, ListCommandEventArgs e) { const string weatherFileName = "c:\\weather.xml"; XmlTextReader weatherReader = null; weatherReader = new XmlTextReader (weatherFileName); String selectedcity = e.ListItem.Value; while (weatherReader.Read()) { if (weatherReader.NodeType == XmlNodeType.Element) { if (weatherReader.Name == e.ListItem.Value) { WeatherLabel = e.ListItem.Text + "\nWeather"; if (weatherReader.LocalName.Equals("updated")) { WeatherLabel = WeatherLabel + "\n" + weatherReader.ReadString(); } if (weatherReader.LocalName.Equals("city")) { WeatherLabel = WeatherLabel + weatherReader.ReadString(); } if (weatherReader.LocalName.Equals("forecast")) { WeatherLabel = WeatherLabel + weatherReader.ReadString(); } if (weatherReader.LocalName.Equals("min")) { WeatherLabel = WeatherLabel + "Min Temperature:" + weatherReader.ReadString(); } if (weatherReader.LocalName.Equals("max")) { WeatherLabel = WeatherLabel + "Max Temperature:" + weatherReader.ReadString ); } } }| } ActiveForm = weather; } </script> //List of cities <mobile:Form runat="server" ID="Form1" NAME="Form1"> <mobile:Label runat="server" ID="Label1" NAME="Label1"> Select a City </mobile:Label> <mobile:List runat="server" id="Listcityvalue" OnItemCommand="List_ClickEventHandler" > <item Text="Auckland" Value="auckland" /> <item Text="Chennai" Value="chennai" /> <item Text="Hong Kong" Value="hongkong" /> <item Text="Mumbai" Value="mumbai" /> <item Text="Malaysia" Value="malaysia" /> <item Text="New Delhi" Value="newdelhi" /> <item Text="New York" Value="newyork" /> <item Text="Sydney" Value="sydney" /> <item Text="Singapore" Value="singapore" /> <item Text="Tokyo" Value="tokyo" /> <item Text="Washington" Value="washington" /> </mobile:List> </mobile:Form> <mobile:Form runat="server" id="SecondForm"> <mobile:Label runat="server" id="WelcomeMessage" /> </mobile:Form> <mobile:Form id="weather" runat = "server"> <mobile:Label runat="server" id="WeatherLabel"/> </mobile:Form> //Source Code End
|
|
Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post
Here.
|
|
|
|
|
Login
to add your contents and source code to this article
|
|
|
|
|
|
|
|
|
|
|
|
Jayachandran Ramadurai
Jayachandran Ramadurai has been Developing different kinds of applications for Wireless Industry like WAP Portal & SMS services using JAVA and Microsoft Technologies.
|
|
|
|
|
|
|
|
|
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional
consulting company, our consultants are well-known experts in .NET and many of them
are MVPs, authors, and trainers. We specialize in Microsoft .NET development and
utilize Agile Development and Extreme Programming practices to provide fast pace
quick turnaround results. Our software development model is a mix of Agile Development,
traditional SDLC, and Waterfall models.
|
|
Click here to learn more about C# Consulting. |
|
|
|
|
|
|
|
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon.
Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees.
As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
|
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
|
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
|
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
|
|
|
|
|
|
|
|
|
|
|
|
|