Question: Help me to create a C# XML file (a student list with first name, last name, state, and favorite color) that your.ASPX page reads and
Help me to create a C# XML file (a student list with first name, last name, state, and favorite color) that your.ASPX page reads and displays. Could you walk me through the procedure for making the XML file and how to create the XML reader? The problem I am having is putting it all together I made the XML file after that I get lost. Can you help me write the html source code. Then do you put anything in the design view if so what would you put their and finaly how do you get to where you put the behind code and can you show If I put my code to read my XML file there . Can someone show me how to put everything together? This is my XML file and code to read my XML File:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml;
namespace XMLdemo2 { class program { static void Main(string[] args) { // Start with XmlReader object //here, we try to setup Stream between the XML file and xmlReader using (XmlReader reader = XmlReader.Create(@"C:\Users\Darren\Documents\Visual Studio 2015\WebSites\WebSite7\myData")) { while (reader.Read()) { if (reader.IsStartElement()) { //return only when you have START tag
switch (reader.Name.ToString()) { case "FirstName": Console.WriteLine("First Name of the Element is : " + reader.ReadString()); break;
case "LastName": Console.WriteLine("Last Name of the Element is : " + reader.ReadString()); break; case "State": Console.WriteLine("Your State is : " + reader.ReadString()); break; case "FavoriteColor": Console.WriteLine("Your Favorite color is : " + reader.ReadString()); break; } } Console.WriteLine(""); } } Console.ReadKey(); } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
