Simple XML Exercise plz Help!
-
Part 1: Use XML text writer class to create the following XML file: 1233 Hard disk 12 200 1235 Monitor 10 300 Part 2: Use the XMLTextReader to read the file created in the Part 1 and display data as shown below: Hardisk 12 200 Monitor 10 300 I already done Part 1 but i can't done Part 2, I am newbie, Plz Help. Thanksssssssssssss -- modified at 2:49 Tuesday 25th April, 2006
-
Part 1: Use XML text writer class to create the following XML file: 1233 Hard disk 12 200 1235 Monitor 10 300 Part 2: Use the XMLTextReader to read the file created in the Part 1 and display data as shown below: Hardisk 12 200 Monitor 10 300 I already done Part 1 but i can't done Part 2, I am newbie, Plz Help. Thanksssssssssssss -- modified at 2:49 Tuesday 25th April, 2006
-
Easiest way is to Load this xml into a dataset and read this from the dataset
DataSet ds=new DataSet();
ds.ReadXml("Filepath");)Ohh, thanks alots :) I tried so hard and got so far
-
Part 1: Use XML text writer class to create the following XML file: 1233 Hard disk 12 200 1235 Monitor 10 300 Part 2: Use the XMLTextReader to read the file created in the Part 1 and display data as shown below: Hardisk 12 200 Monitor 10 300 I already done Part 1 but i can't done Part 2, I am newbie, Plz Help. Thanksssssssssssss -- modified at 2:49 Tuesday 25th April, 2006
USE THIS CODE U WILL GET UR REQUIRED FORMAT using System; using System.Xml; namespace ConsoleApplication1 { class Class1 { static void Main(string[] args) { XmlTextReader reader =new XmlTextReader("path of file"); string id=null; string productname=null; string quantity=null; string unitprice=null; while(reader.Read()) { switch(reader.NodeType.ToString()) { case "Element": switch(reader.Name.ToString()) { case "id" : id = reader.ReadElementString().ToString(); break; case "productname": productname = reader.ReadElementString().ToString(); break; case "quantity": quantity = reader.ReadElementString().ToString(); break; case "unitprice": unitprice = reader.ReadElementString().ToString(); break; } break; case "EndElement": if( reader.Name.ToString() == "item") { Console.WriteLine(id +" "+ productname +" "+ quantity +" "+ unitprice); id=null; productname=null; quantity=null; unitprice=null; } break; } }//while } } }