FILTER IN A XML FILE IN C#

Manoj Bhatt

Total Post:154

Points:1086
Posted by  Manoj Bhatt
C# 
C#
 1323  View(s)
Ratings:
Rate this:
Hi Experts,

How to filter in a XML file in C#?

Thanks in advance.

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: Filter in a XML file in C#

    Hi Manoj,


    The following code will solve your problem:

    using System;

    using System.Data;

    using System.Windows.Forms;

    using System.Xml;

     

    namespace WindowsApplication1

    {

        public partial class Form1 : Form

        {

            public Form1()

            {

                InitializeComponent();

            }

     

            private void button1_Click(object sender, EventArgs e)

            {

                XmlReader xmlFile;

                xmlFile = XmlReader.Create("Product.xml", new XmlReaderSettings());

                DataSet ds = new DataSet();

                DataView dv;

                ds.ReadXml(xmlFile);

                dv = new DataView(ds.Tables[0], "Product_price > = 3000", "Product_Name", DataViewRowState.CurrentRows);

                dv.ToTable().WriteXml("Result.xml");

                MessageBox.Show("Done");

            }

        }

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!