Sorting

  • Thread starter Thread starter Eregnon
  • Start date Start date
E

Eregnon

Guest
Is there any way of sorting an xml file in vb.net? The two methods described in the documentation - select and dataview.sort - dont seem to physically reorder the records.
 
Order is, in most cases, rather irrelevant when it comes to XML, so I doubt the framework includes built-in methods for rearranging the entries in the XML file.
 
How about rearranging the order of any file, or doing any sorting at all? Ive got an xml file I read into a dataset that is bound to controls on a form - using the binding context. No matter how I set the select or default view sort criteria, it always displays in the order of the file.
 
Never mind, I figured out how to do it. Heres a quick sample in case anyones interested:
Code:
        Dim dsTemp As New DataSet
        Dim dRows() As DataRow
        Dim dsReal as new DataSet

        dsTemp.ReadXml("xmlfilename.xml", XmlReadMode.Auto)
        dRows = dsTemp.Tables("tablename").Select("", "DisplayOrder")


        For k = 0 To dRows.Length - 1
            dsReal.Tables("tablename").ImportRow(dRows(k))
      
        Next
You have to use importrow, since using the rows.add method generates an error. Kind of clumsy, but if you need the physical order of a file changed, I think this is the only way to do it.
 
Back
Top