xml parsing in c#

Kamlesh420
Posted by in ADO.NET category on for Intermediate level | Points: 250 | Views : 4784 red flag

In this article we will look into how we can parse the XML request

Introduction

Hope you all enjoying the coding. As you all know XMLData is small code to access XML file as a small database. If your application is small, doesn't need very secure access, and do you want user to install and maintain any database engine. XMLData provides simple access using the power of ADO.NET

Objective

The objective of this article to help the developer to parse the XML and save that value in the DataTable in simple way. This can be done in two ways

1. By Visiting each and every node Of XML and get Value from it.
2. By loading XML in DATASET.

Using the code

We have the following XML Response from a web service

<OTA_VehAvailRateRS>
<Success />
<Warnings>
<Warning Type="1" ShortText="RATE SUBJECT TO CHANGE" RecordID="157" />
<Warning Type="1" ShortText="ONE WAY RENTAL CONFIRMED" RecordID="236" />
<Warning Type="1" ShortText="REQUESTED VEHICLE NOT AVAIL-ALTERNATES OFFERED" RecordID="283" />
</Warnings>
<VehAvailRSCore>
<VehRentalCore PickUpDateTime="2013-09-14T09:00:00-05:00" ReturnDateTime="2013-09-16T09:09:00-05:00">
<PickUpLocation ExtendedLocationCode="AUHT50" LocationCode="AUH" />
<ReturnLocation ExtendedLocationCode="DXBT50" LocationCode="DXB" />
</VehRentalCore>
<VehVendorAvails>
<VehVendorAvail>
<Vendor Code="ZE" />
<VehAvails>
<VehAvail>
<VehAvailCore Status="Available" IsAlternateInd="false">
<Vehicle PassengerQuantity="5" BaggageQuantity="3" AirConditionInd="true" TransmissionType="Automatic" FuelType="Unspecified" DriveType="Unspecified" Code="EDAR" CodeContext="SIPP">
<VehType VehicleCategory="1" DoorCount="4" />
<VehClass Size="3" />
<VehMakeModel Name="B TOYOTA YARIS OR SIMILAR" Code="EDAR" />
<PictureURL>ZEAEEDAR999.jpg</PictureURL>
</Vehicle>
<RentalRate>
<RateDistance Unlimited="true" DistUnitName="Km" VehiclePeriodUnitName="RentalPeriod" />
<VehicleCharges>
<VehicleCharge Purpose="1" TaxInclusive="false" GuaranteedInd="false" Amount="482.00" CurrencyCode="AED">
<Calculation UnitCharge="241.00" UnitName="Day" Quantity="2" />
</VehicleCharge>
</VehicleCharges>
<RateQualifier ArriveByFlight="false" RateCategory="3" RateQualifier="RUD" />
</RentalRate>
<TotalCharge RateTotalAmount="482.00" EstimatedTotalAmount="522.00" CurrencyCode="AED" />
<Fees>
<Fee Purpose="5" TaxInclusive="false" Description="LOCATION SERVICE CHARGE:" IncludedInRate="false" Amount="30.00" CurrencyCode="AED" />
<Fee Purpose="5" TaxInclusive="false" Description="VEHICLE LICENSING FEE AND ROAD TAX:" IncludedInRate="false" Amount="10.00" CurrencyCode="AED" />
</Fees>
<Reference Type="16" ID="08375HD3SG27410-2501" />
</VehAvailCore>
<VehAvailInfo>
<PricedCoverages>
<PricedCoverage Required="false">
<Coverage CoverageType="7" />
<Charge TaxInclusive="false" IncludedInRate="false" CurrencyCode="AED">
<Calculation UnitCharge="35.00" UnitName="Day" Quantity="1" />
</Charge>
</PricedCoverage>
<PricedCoverage Required="false">
<Coverage CoverageType="38" />
<Charge TaxInclusive="false" IncludedInRate="false" CurrencyCode="AED">
<Calculation UnitCharge="20.00" UnitName="Day" Quantity="1" />
</Charge>
</PricedCoverage>
<PricedCoverage Required="false">
<Coverage CoverageType="40" />
<Charge TaxInclusive="false" IncludedInRate="false" CurrencyCode="AED">
<Calculation UnitCharge="25.00" UnitName="Day" Quantity="1" />
</Charge>
</PricedCoverage>
</PricedCoverages>
</VehAvailInfo>
</VehAvail>
<VehAvail>
<VehAvailCore Status="Available" IsAlternateInd="false">
<Vehicle PassengerQuantity="5" BaggageQuantity="3" AirConditionInd="true" TransmissionType="Automatic" FuelType="Unspecified" DriveType="Unspecified" Code="EDAR" CodeContext="SIPP">
<VehType VehicleCategory="1" DoorCount="4" />
<VehClass Size="3" />
<VehMakeModel Name="B TOYOTA YARIS OR SIMILAR" Code="EDAR" />
<PictureURL>ZEAEEDAR999.jpg</PictureURL>
</Vehicle>
<RentalRate>
<RateDistance Unlimited="true" DistUnitName="Km" VehiclePeriodUnitName="RentalPeriod" />
<VehicleCharges>
<VehicleCharge Purpose="1" TaxInclusive="false" GuaranteedInd="false" Amount="482.00" CurrencyCode="AED">
<Calculation UnitCharge="241.00" UnitName="Day" Quantity="2" />
</VehicleCharge>
</VehicleCharges>
<RateQualifier ArriveByFlight="false" RateCategory="3" RateQualifier="RUD" />
</RentalRate>
<TotalCharge RateTotalAmount="482.00" EstimatedTotalAmount="522.00" CurrencyCode="AED" />
<Fees>
<Fee Purpose="5" TaxInclusive="false" Description="LOCATION SERVICE CHARGE:" IncludedInRate="false" Amount="30.00" CurrencyCode="AED" />
<Fee Purpose="5" TaxInclusive="false" Description="VEHICLE LICENSING FEE AND ROAD TAX:" IncludedInRate="false" Amount="10.00" CurrencyCode="AED" />
</Fees>
<Reference Type="16" ID="08375HD3SG27410-2501" />
</VehAvailCore>
<VehAvailInfo>
<PricedCoverages>
<PricedCoverage Required="false">
<Coverage CoverageType="7" />
<Charge TaxInclusive="false" IncludedInRate="false" CurrencyCode="AED">
<Calculation UnitCharge="35.00" UnitName="Day" Quantity="1" />
</Charge>
</PricedCoverage>
<PricedCoverage Required="false">
<Coverage CoverageType="38" />
<Charge TaxInclusive="false" IncludedInRate="false" CurrencyCode="AED">
<Calculation UnitCharge="20.00" UnitName="Day" Quantity="1" />
</Charge>
</PricedCoverage>
<PricedCoverage Required="false">
<Coverage CoverageType="40" />
<Charge TaxInclusive="false" IncludedInRate="false" CurrencyCode="AED">
<Calculation UnitCharge="25.00" UnitName="Day" Quantity="1" />
</Charge>
</PricedCoverage>
</PricedCoverages>
</VehAvailInfo>
</VehAvail>
<VehAvail>
<VehAvailCore Status="Available" IsAlternateInd="false">
<Vehicle PassengerQuantity="5" BaggageQuantity="3" AirConditionInd="true" TransmissionType="Automatic" FuelType="Unspecified" DriveType="Unspecified" Code="EDAR" CodeContext="SIPP">
<VehType VehicleCategory="1" DoorCount="4" />
<VehClass Size="3" />
<VehMakeModel Name="B TOYOTA YARIS OR SIMILAR" Code="EDAR" />
<PictureURL>ZEAEEDAR999.jpg</PictureURL>
</Vehicle>
<RentalRate>
<RateDistance Unlimited="true" DistUnitName="Km" VehiclePeriodUnitName="RentalPeriod" />
<VehicleCharges>
<VehicleCharge Purpose="1" TaxInclusive="false" GuaranteedInd="false" Amount="482.00" CurrencyCode="AED">
<Calculation UnitCharge="241.00" UnitName="Day" Quantity="2" />
</VehicleCharge>
</VehicleCharges>
<RateQualifier ArriveByFlight="false" RateCategory="3" RateQualifier="RUD" />
</RentalRate>
<TotalCharge RateTotalAmount="482.00" EstimatedTotalAmount="522.00" CurrencyCode="AED" />
<Fees>
<Fee Purpose="5" TaxInclusive="false" Description="LOCATION SERVICE CHARGE:" IncludedInRate="false" Amount="30.00" CurrencyCode="AED" />
<Fee Purpose="5" TaxInclusive="false" Description="VEHICLE LICENSING FEE AND ROAD TAX:" IncludedInRate="false" Amount="10.00" CurrencyCode="AED" />
</Fees>
<Reference Type="16" ID="08375HD3SG27410-2501" />
</VehAvailCore>
<VehAvailInfo>
<PricedCoverages>
<PricedCoverage Required="false">
<Coverage CoverageType="7" />
<Charge TaxInclusive="false" IncludedInRate="false" CurrencyCode="AED">
<Calculation UnitCharge="35.00" UnitName="Day" Quantity="1" />
</Charge>
</PricedCoverage>
<PricedCoverage Required="false">
<Coverage CoverageType="38" />
<Charge TaxInclusive="false" IncludedInRate="false" CurrencyCode="AED">
<Calculation UnitCharge="20.00" UnitName="Day" Quantity="1" />
</Charge>
</PricedCoverage>
<PricedCoverage Required="false">
<Coverage CoverageType="40" />
<Charge TaxInclusive="false" IncludedInRate="false" CurrencyCode="AED">
<Calculation UnitCharge="25.00" UnitName="Day" Quantity="1" />
</Charge>
</PricedCoverage>
</PricedCoverages>
</VehAvailInfo>
</VehAvail>
<VehAvail>
<VehAvailCore Status="Available" IsAlternateInd="false">
<Vehicle PassengerQuantity="5" BaggageQuantity="3" AirConditionInd="true" TransmissionType="Automatic" FuelType="Unspecified" DriveType="Unspecified" Code="EDAR" CodeContext="SIPP">
<VehType VehicleCategory="1" DoorCount="4" />
<VehClass Size="3" />
<VehMakeModel Name="B TOYOTA YARIS OR SIMILAR" Code="EDAR" />
<PictureURL>ZEAEEDAR999.jpg</PictureURL>
</Vehicle>
<RentalRate>
<RateDistance Unlimited="true" DistUnitName="Km" VehiclePeriodUnitName="RentalPeriod" />
<VehicleCharges>
<VehicleCharge Purpose="1" TaxInclusive="false" GuaranteedInd="false" Amount="482.00" CurrencyCode="AED">
<Calculation UnitCharge="241.00" UnitName="Day" Quantity="2" />
</VehicleCharge>
</VehicleCharges>
<RateQualifier ArriveByFlight="false" RateCategory="3" RateQualifier="RUD" />
</RentalRate>
<TotalCharge RateTotalAmount="482.00" EstimatedTotalAmount="522.00" CurrencyCode="AED" />
<Fees>
<Fee Purpose="5" TaxInclusive="false" Description="LOCATION SERVICE CHARGE:" IncludedInRate="false" Amount="30.00" CurrencyCode="AED" />
<Fee Purpose="5" TaxInclusive="false" Description="VEHICLE LICENSING FEE AND ROAD TAX:" IncludedInRate="false" Amount="10.00" CurrencyCode="AED" />
</Fees>
<Reference Type="16" ID="08375HD3SG27410-2501" />
</VehAvailCore>
<VehAvailInfo>
<PricedCoverages>
<PricedCoverage Required="false">
<Coverage CoverageType="7" />
<Charge TaxInclusive="false" IncludedInRate="false" CurrencyCode="AED">
<Calculation UnitCharge="35.00" UnitName="Day" Quantity="1" />
</Charge>
</PricedCoverage>
<PricedCoverage Required="false">
<Coverage CoverageType="38" />
<Charge TaxInclusive="false" IncludedInRate="false" CurrencyCode="AED">
<Calculation UnitCharge="20.00" UnitName="Day" Quantity="1" />
</Charge>
</PricedCoverage>
<PricedCoverage Required="false">
<Coverage CoverageType="40" />
<Charge TaxInclusive="false" IncludedInRate="false" CurrencyCode="AED">
<Calculation UnitCharge="25.00" UnitName="Day" Quantity="1" />
</Charge>
</PricedCoverage>
</PricedCoverages>
</VehAvailInfo>
</VehAvail>
</VehAvails>




<Info>
<LocationDetails Name="ABU DHABI AIRPORT">
<Address FormattedInd="false">
<AddressLine>ABU DHABI AIRPORT</AddressLine>
<AddressLine>SKY PARK PLAZA, 4TH LEVEL</AddressLine>
<CityName>ABU DHABI</CityName>
<PostalCode>32063</PostalCode>
<CountryName Code="AE">UNITED ARAB EMIRATES</CountryName>
</Address>
<Telephone PhoneLocationType="4" PhoneTechType="1" PhoneNumber="25998939" FormattedInd="false" />
<AdditionalInfo>
<OperationSchedules>
<OperationSchedule>
<OperationTimes>
<OperationTime Text="MO-SU 24HRS" />
<OperationTime Mon="true" Start="00:01" End="23:59" />
<OperationTime Tue="true" Start="00:01" End="23:59" />
<OperationTime Weds="true" Start="00:01" End="23:59" />
<OperationTime Thur="true" Start="00:01" End="23:59" />
<OperationTime Fri="true" Start="00:01" End="23:59" />
<OperationTime Sat="true" Start="00:01" End="23:59" />
<OperationTime Sun="true" Start="00:01" End="23:59" />
</OperationTimes>
</OperationSchedule>
</OperationSchedules>
</AdditionalInfo>
</LocationDetails>
</Info>
</VehVendorAvail>
</VehVendorAvails>
</VehAvailRSCore>
</OTA_VehAvailRateRS>











Now Lets look at a method how to parse it

1)By Visiting each and every node Of XML and get Value from it.

protected void Page_Load(object sender, EventArgs e)
{
XmlDocument xmlresponse = new XmlDocument();
xmlresponse.Load(HttpContext.Current.Server.MapPath("XMLFile2.xml"));
viewSearch(xmlresponse.InnerXml);
}
public DataTable viewSearch(string strResponseXML)
{
XmlDocument rdoc = new XmlDocument();
XmlDocument doc = new XmlDocument();
rdoc.InnerXml = strResponseXML;
string newres;
newres = rdoc.GetElementsByTagName("OTA_VehAvailRateRS")[0].InnerXml;
XmlDocument xmlRes = new XmlDocument();
xmlRes.LoadXml(rdoc.InnerXml);
DataTable dtAdd = new DataTable("VehAvailRSCore");
dtAdd.Columns.Add("PickUpDateTime", System.Type.GetType("System.String"));
dtAdd.Columns.Add("ReturnDateTime", System.Type.GetType("System.String"));
dtAdd.Columns.Add("PickLocationCode", System.Type.GetType("System.String"));
dtAdd.Columns.Add("ReturnLocationCode", System.Type.GetType("System.String"));
dtAdd.Columns.Add("VendorCode", System.Type.GetType("System.String"));
dtAdd.Columns.Add("Status", System.Type.GetType("System.String"));
dtAdd.Columns.Add("PassengerQuantity", System.Type.GetType("System.String"));
dtAdd.Columns.Add("BaggageQuantity", System.Type.GetType("System.String"));
dtAdd.Columns.Add("AirCondition", System.Type.GetType("System.String"));
dtAdd.Columns.Add("TransmissionType", System.Type.GetType("System.String"));
dtAdd.Columns.Add("FuelType", System.Type.GetType("System.String"));
dtAdd.Columns.Add("DriveType", System.Type.GetType("System.String"));
dtAdd.Columns.Add("VehMakeModelName", System.Type.GetType("System.String"));
dtAdd.Columns.Add("VehMakeModelCode", System.Type.GetType("System.String"));
dtAdd.Columns.Add("PictureURL", System.Type.GetType("System.String"));
dtAdd.Columns.Add("RateTotalAmount", System.Type.GetType("System.String"));
dtAdd.Columns.Add("EstimatedTotalAmount", System.Type.GetType("System.String"));
dtAdd.Columns.Add("CurrencyCode", System.Type.GetType("System.String"));
dtAdd.Columns.Add("LocationDetailsName", System.Type.GetType("System.String"));
dtAdd.Columns.Add("AddressLine", System.Type.GetType("System.String"));
dtAdd.Columns.Add("AddressLine1", System.Type.GetType("System.String"));
dtAdd.Columns.Add("CityName", System.Type.GetType("System.String"));
dtAdd.Columns.Add("PostalCode", System.Type.GetType("System.String"));
dtAdd.Columns.Add("CountryCode", System.Type.GetType("System.String"));
dtAdd.Columns.Add("CountryName", System.Type.GetType("System.String"));
dtAdd.Columns.Add("PhoneNumber", System.Type.GetType("System.String"));

try
{
//xmlRes.LoadXml(rdoc.InnerXml);
DataRow dr;
if (xmlRes.DocumentElement.SelectSingleNode("VehAvailRSCore") != null)
{
string PickUpDateTime = xmlRes.DocumentElement.SelectSingleNode("VehAvailRSCore/VehRentalCore/@PickUpDateTime").InnerText;
string ReturnDateTime = xmlRes.DocumentElement.SelectSingleNode("VehAvailRSCore/VehRentalCore/@ReturnDateTime").InnerText;
string PickLocationCode = xmlRes.DocumentElement.SelectSingleNode("VehAvailRSCore/VehRentalCore/PickUpLocation/@LocationCode").InnerText;
string ReturnLocationCode = xmlRes.DocumentElement.SelectSingleNode("VehAvailRSCore/VehRentalCore/ReturnLocation/@LocationCode").InnerText;
string VendorCode = xmlRes.DocumentElement.SelectSingleNode("VehAvailRSCore/VehVendorAvails/VehVendorAvail/Vendor/@Code").InnerText;
string LocationDetailsName = xmlRes.DocumentElement.SelectSingleNode("VehAvailRSCore/VehVendorAvails/VehVendorAvail/Info/LocationDetails/@Name").InnerText;
string AddressLine = xmlRes.DocumentElement.SelectSingleNode("VehAvailRSCore/VehVendorAvails/VehVendorAvail/Info/LocationDetails/Address/AddressLine").InnerText;
string AddressLine1 = xmlRes.DocumentElement.SelectSingleNode("VehAvailRSCore/VehVendorAvails/VehVendorAvail/Info/LocationDetails/Address/AddressLine1").InnerText;
string CityName = xmlRes.DocumentElement.SelectSingleNode("VehAvailRSCore/VehVendorAvails/VehVendorAvail/Info/LocationDetails/Address/CityName").InnerText;
string PostalCode = xmlRes.DocumentElement.SelectSingleNode("VehAvailRSCore/VehVendorAvails/VehVendorAvail/Info/LocationDetails/Address/PostalCode").InnerText;
string CountryCode = xmlRes.DocumentElement.SelectSingleNode("VehAvailRSCore/VehVendorAvails/VehVendorAvail/Info/LocationDetails/Address/CountryName/@Code").InnerText;
string CountryName = xmlRes.DocumentElement.SelectSingleNode("VehAvailRSCore/VehVendorAvails/VehVendorAvail/Info/LocationDetails/Address/CountryName").InnerText;
string PhoneNumber = xmlRes.DocumentElement.SelectSingleNode("VehAvailRSCore/VehVendorAvails/VehVendorAvail/Info/LocationDetails/Telephone/@PhoneNumber").InnerText;
foreach (XmlNode xmlAdd in xmlRes.DocumentElement.SelectNodes("VehAvailRSCore/VehVendorAvails/VehVendorAvail/VehAvails/VehAvail"))
{



dr = dtAdd.NewRow();
dr["PickUpDateTime"] = PickUpDateTime;
dr["ReturnDateTime"] = ReturnDateTime;
dr["PickLocationCode"] = PickLocationCode;
dr["ReturnLocationCode"] = ReturnLocationCode;
dr["VendorCode"] = VendorCode;
dr["Status"] = xmlAdd.SelectSingleNode("VehAvailCore/@Status").InnerText;
dr["PassengerQuantity"] = xmlAdd.SelectSingleNode("VehAvailCore/Vehicle/@PassengerQuantity").InnerText;
dr["BaggageQuantity"] = xmlAdd.SelectSingleNode("VehAvailCore/Vehicle/@BaggageQuantity").InnerText;
dr["AirCondition"] = xmlAdd.SelectSingleNode("VehAvailCore/Vehicle/@AirConditionInd").InnerText;
dr["TransmissionType"] = xmlAdd.SelectSingleNode("VehAvailCore/Vehicle/@TransmissionType").InnerText;
dr["FuelType"] = xmlAdd.SelectSingleNode("VehAvailCore/Vehicle/@FuelType").InnerText;
dr["DriveType"] = xmlAdd.SelectSingleNode("VehAvailCore/Vehicle/@DriveType").InnerText;
dr["VehMakeModelName"] = xmlAdd.SelectSingleNode("VehAvailCore/Vehicle/VehMakeModel/@Name").InnerText;
dr["VehMakeModelCode"] = xmlAdd.SelectSingleNode("VehAvailCore/Vehicle/VehMakeModel/@Code").InnerText;
string PictureURL = xmlAdd.SelectSingleNode("VehAvailCore/Vehicle/PictureURL").InnerText;
if (CountryName.ToUpper() == "UNITED STATES")
{
dr["PictureURL"] = PictureURL;
}
else
{
dr["PictureURL"] = PictureURL;
}
dr["RateTotalAmount"] = xmlAdd.SelectSingleNode("VehAvailCore/TotalCharge/@RateTotalAmount").InnerText;
dr["EstimatedTotalAmount"] = xmlAdd.SelectSingleNode("VehAvailCore/TotalCharge/@EstimatedTotalAmount").InnerText;
dr["CurrencyCode"] = xmlAdd.SelectSingleNode("VehAvailCore/TotalCharge/@CurrencyCode").InnerText;
dr["LocationDetailsName"] = LocationDetailsName;
dr["AddressLine"] = AddressLine;
dr["AddressLine1"] = AddressLine1;
dr["CityName"] = CityName;
dr["PostalCode"] = PostalCode;
dr["CountryCode"] = CountryCode;
dr["CountryName"] = CountryName;
dr["PhoneNumber"] = PhoneNumber;
dtAdd.Rows.Add(dr);
}
}
}
catch
{
}
return dtAdd;
}


2. By loading XML in DATASET.

 protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataSet ds = new DataSet();
XmlDocument xmlresponse = new XmlDocument();
xmlresponse.Load(HttpContext.Current.Server.MapPath("XMLFile2.xml"));
XmlNodeReader xmlreader = new XmlNodeReader(xmlresponse);
ds.ReadXml(xmlreader);
Session["result"] = ds;
//bind search result
RPcarlist.DataSource = MasterDatatable(ds);



}
}







private DataTable MasterDatatable(DataSet ds)
{
DataTable dtcar = new DataTable();
DataTable dtmaster = new DataTable();
DataTable door = new DataTable();
dtmaster.Columns.Add("Vid");
dtmaster.Columns.Add("Vname");
dtmaster.Columns.Add("Passengers");
dtmaster.Columns.Add("Luaggage");
dtmaster.Columns.Add("AirConditioning");
dtmaster.Columns.Add("VehAvailCore_Id");
dtmaster.Columns.Add("Image");
dtmaster.Columns.Add("Door");
dtmaster.Columns.Add("Code");
dtmaster.Columns.Add("TransmissionType");
dtmaster.Columns.Add("RateTotalAmount");
dtmaster.Columns.Add("EstimatedTotalAmount");
dtmaster.Columns.Add("CurrencyCode");

dtcar = ds.Tables["vehicle"];
for (int i = 0; i < dtcar.Rows.Count; i++)
{
DataRow dr = dtmaster.NewRow();
dr["Vid"] = dtcar.Rows[i]["Vehicle_Id"];
dr["Passengers"] = "<img src=\"images/person.png\" />" + dtcar.Rows[i]["PassengerQuantity"];
dr["Luaggage"] = "<img src=\"images/Luggage.png\" />" + dtcar.Rows[i]["BaggageQuantity"];
if (dtcar.Rows[i]["AirConditionInd"].ToString() == "true")
{
dr["AirConditioning"] = "<img src=\"images/Ac.png\" />" + "Air Conditioning";
}
dr["Image"] = "<img src=\"http://fggddf.com/ve/" + dtcar.Rows[i]["PictureURL"] + "\" width=\"220px\"height=\"128px\" />";
dr["TransmissionType"] = " <img src=\"images/Transmistion.png\" />&nbsp;" + dtcar.Rows[i]["TransmissionType"];
dr["VehAvailCore_Id"] = dtcar.Rows[i]["VehAvailCore_Id"];
string VehAvailCore_Id = dtcar.Rows[i]["VehAvailCore_Id"].ToString();
#region Get Vehicle Name And Model
DataTable dtmodel = new DataTable();
dtmodel = ds.Tables["VehMakeModel"];
DataView dvmodel = dtmodel.DefaultView;
dvmodel.RowFilter = "Vehicle_Id='" + i + "'";
dtmodel = dvmodel.ToTable();
dr["Vname"] = dtmodel.Rows[0]["Name"];
dr["Code"] = dtmodel.Rows[0]["Code"];
#endregion
#region Get door
DataTable dttemp = new DataTable();
door = ds.Tables["VehType"];
DataView DV = door.DefaultView;
DV.RowFilter = "Vehicle_Id='" + i + "'";
dttemp = DV.ToTable();
dr["Door"] = dttemp.Rows[0]["DoorCount"];
#endregion
#region get Charges

DataTable dtcharges = new DataTable();
dtcharges = ds.Tables["TotalCharge"];
DataView DVcharges = dtcharges.DefaultView;
DVcharges.RowFilter = "VehAvailCore_Id='" + VehAvailCore_Id + "'";
dtcharges = DVcharges.ToTable();
dr["RateTotalAmount"] = dtcharges.Rows[0]["RateTotalAmount"];
dr["EstimatedTotalAmount"] = dtcharges.Rows[0]["EstimatedTotalAmount"];
dr["CurrencyCode"] = dtcharges.Rows[0]["CurrencyCode"];


#endregion
dtmaster.Rows.Add(dr);
}
return dtmaster;

}

Conclusion

so you can now Parse in a simple way
please comment  if you having any doubts.


Page copy protected against web site content infringement by Copyscape

About the Author

Kamlesh420
Full Name: kamlesh saini
Member Level: Starter
Member Status: Member
Member Since: 12/8/2011 3:06:35 AM
Country: India
kamlesh kuamr saini Sr. devloper (asp.net) new delhi


Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)