Home > DeveloperSection > Forums > Filter in a XML file in C#
Manoj Bhatt
Manoj Bhatt

Total Post:153

Points:1079
Posted on    June-15-2013 5:18 AM

 C# C# 
Ratings:


 1 Reply(s)
 1067  View(s)
Rate this:
Hi Experts,

How to filter in a XML file in C#?

Thanks in advance.



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    June-15-2013 7:18 AM

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");

        }

    }

}


Don't want to miss updates? Please click the below button!

Follow MindStick