Sorting an XML file

  • Thread starter Thread starter Leszek
  • Start date Start date
L

Leszek

Hello,

I need to sort an XML file and then display the result in a drop-down list
on an ASP.NET WebForm.
What should I use? DataSet, DataReader, something else? Right now I have the
following code:

DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("categories.xml"), XmlReadMode.InferSchema);
cboType.DataSource = ds;
cboType.DataBind();

Thanks for any help,
Leszek Taratuta
 
Hi Leszek,

Use DataView:
DataView dv = new DataView(ds.Tables[0], string.Empty, "Column1 ASC",
DataViewRowState.CurrentRows);
// this sorts by column1 ascending - you might add other columns, too.
// then just bind the dataview instead of dataset (adjust DataMember too).
cboType.DataSource = dv;
 
Thanks a lot. It works fine.

I'm just wondering if there would be any other method to sort XML files
without using DataSets and DataViews. Would it be possible to use XSLT?

Thanks,
Leszek Taratuta

Miha Markic said:
Hi Leszek,

Use DataView:
DataView dv = new DataView(ds.Tables[0], string.Empty, "Column1 ASC",
DataViewRowState.CurrentRows);
// this sorts by column1 ascending - you might add other columns, too.
// then just bind the dataview instead of dataset (adjust DataMember too).
cboType.DataSource = dv;

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com


Leszek said:
Hello,

I need to sort an XML file and then display the result in a drop-down list
on an ASP.NET WebForm.
What should I use? DataSet, DataReader, something else? Right now I have the
following code:

DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("categories.xml"), XmlReadMode.InferSchema);
cboType.DataSource = ds;
cboType.DataBind();

Thanks for any help,
Leszek Taratuta
 
Back
Top