Suppose we have an XML file "Customer.xml", whose values we want to read.
XmlReader
xml = XmlReader.Create(Server.MapPath("Customer.xml"), new XmlReaderSettings());
If you debug the page and place a break point at the "dt.ReadXml(xml);", you can see that the DataSet is filled with the values present in the XML FIle.
Step-1: Add a page to your solution and place a button in it.
<asp:Button ID="btnReadXML" runat="server" Text="Read XML"
onclick="btnReadXML_Click"
/>
Step-2: Write these following lines in the Button's Click Event.
protected void
btnReadXML_Click(object sender, EventArgs e)
{
|
DataSet dt = new DataSet();
dt.ReadXml(xml);
for (int i = 0; i
< dt.Tables[0].Rows.Count; i++)
{
Response.Write(dt.Tables[0].Rows[i].ItemArray[2].ToString()+"<br/>");
}
}
If you debug the page and place a break point at the "dt.ReadXml(xml);", you can see that the DataSet is filled with the values present in the XML FIle.
Output: As we are sending only the Values of 3rd column(Customer Name") to the front, it will print only the customers Name.
Regards,
Prajanuranjan....
No comments:
Post a Comment