SiteMap  | About    

How to filter in a XML file

XML is a platform independent language, so the information formatted in XML can be used in any other platforms (Operating Systems). Once we create an XML file in one platform it can be used in other platforms also. The .Net technology is widely supported XML file format. Also the Dataset in ADO.NET uses XML format as its internal storage format.

Here we are going to filter an XML file content and store the result in a newly created XML file through C#. We have an XML file Product.XML , and it has a field Product_Price. We are giving a search criteria like the Product_Price >= 3000 and store the result in a newly created XML file Result.XML .

using System;
using System.Data;
using System.Windows.Forms;
using System.Xml;

namespace WindowsApplication1
    public partial class Form1 : Form
        public Form1()

        private void button1_Click(object sender, EventArgs e)
            XmlReader xmlFile ;
            xmlFile = XmlReader.Create("Product.xml", new XmlReaderSettings());
            DataSet ds = new DataSet();
            DataView dv ;
            dv = new DataView(ds.Tables[0], "Product_price > = 3000", "Product_Name", DataViewRowState.CurrentRows);
            MessageBox.Show ("Done");

You can see the filter result in Result.xml file
Click here to download the input file product.xml : product.xml (C) 2016    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.