How to read XML File

Posted by Krishnasamy2008 under ASP.NET on 4/6/2011 | Points: 10 | Views : 2231 | Status : [Member] | Replies : 1
Hi Friends,

How to read xml files as below.I stored below format in session.How to read session xml files.

<?xml version="1.0" encoding="utf-16"?>
<ArrayOfTicketSearchCriteria xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<TicketSearchCriteria>
<From>0</TicketIDFrom>
<TO>0</TicketIDTO>
<Template>1,3,5,2,4,6,7</Template>
<Deal>9715,9721,9723,8709,9638,8710,8712,8713,8714,9677,9945,10093,8733,8734,8741,8744,9533,9916,8793,8809,8810,9681,9632,9996,8906,8907,9512,9513,9523,8945,8969,10110,10113,10114,10111,9927,9169,9170,9896,10115,9659,10066,10065,9504</Deal>
</TicketSearchCriteria>
</ArrayOfTicketSearchCriteria>

I need to take Template,Deal,From and To values.

Thanks and regards,
Krishna.K




Responses

Posted by: NDebata on: 4/12/2011 [Member] Starter | Points: 25

Up
0
Down
//I am loading your xml to session
using (StreamReader rdr=new StreamReader(Server.MapPath(@"App_Data\Test.xml")))
{
this.Session["MyXML"]=rdr.ReadToEnd();
}


//Please include : using System.Xml.Linq; to use XElement

XElement xe = XElement.Parse(Convert.ToString(this.Session["MyXML"]),LoadOptions.PreserveWhitespace);
//Please handle null check if required.
string From= xe.Element("TicketSearchCriteria").Element("From").Value;
string To = xe.Element("TicketSearchCriteria").Element("TO").Value;
string Template = xe.Element("TicketSearchCriteria").Element("Template").Value;
string Deal = xe.Element("TicketSearchCriteria").Element("Deal").Value;

Thanks,
Debata

Krishnasamy2008, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response