Link to home
Start Free TrialLog in
Avatar of t_mych
t_mych

asked on

I would like to filter and then group/sort the following XML by the DOCUMENT_TYPE

I would like to filter and then group/sort the following XML by the DOCUMENT_TYPE:
...
- <QITEM EntryID="AAABDpAAIAACRUjAAJ">
  <F_Busy>False</F_Busy>
  <F_Delay />
  <F_EntryTime>7/1/2005 3:37:33 PM</F_EntryTime>
  <F_GroupID />
  <F_Priority>5</F_Priority>
  <F_TimeOut />
  <F_UserID />
  <QDOC_ID>304766820</QDOC_ID>
  <DOCUMENT_TYPE>MED-REFERRAL</DOCUMENT_TYPE>
  <F_DOCUMENTCLASS />
  </QITEM>
- <QITEM EntryID="AAABDpAAIAACRUjAAK">
  <F_Busy>False</F_Busy>
  <F_Delay />
  <F_EntryTime>7/1/2005 3:59:57 PM</F_EntryTime>
  <F_GroupID />
  <F_Priority>5</F_Priority>
  <F_TimeOut />
  <F_UserID />
  <QDOC_ID>304766821</QDOC_ID>
  <DOCUMENT_TYPE>PREFETCH-SHEET</DOCUMENT_TYPE>
  <F_DOCUMENTCLASS />
  </QITEM>
...

I am reading XML file into strongly typed dataset OTHDISTQ and then sorting it by DefaultView.Sort = "DOCUMENT_TYPE" (see code below). The datagrid that is bound to the dataset displays  s o r t e d  data correctly, however i need help figuring out   h o w   t o   s a v e  sorted data back into XML (both approaches below using WriteXML() are not successful at it).
Thanks in advance!


            Dim dsOTHDIST As New OTHDISTQ
            dsOTHDIST.ReadXml("C:\Temp\OTHDISTQ.xml")

            Dim dv As New DataView
            If Not dsOTHDIST Is Nothing Then
                dv.Table = dsOTHDIST.Tables(1)
            End If            

            With dsOTHDIST.Tables(1)
                .DefaultView.Sort = "DOCUMENT_TYPE"
                .DefaultView.Table.AcceptChanges()
                DataGrid1.DataSource = .DefaultView.Table
                .DefaultView.Table.DataSet.WriteXml("C:\Temp\XMLData\OTHDISTQ.xml")
            End With
           
            Dim dsSorted As New DataTable
            Dim objDataSource As Object = DataGrid1.DataSource
            dsSorted = DirectCast(objDataSource, DataTable)
            dsSorted.DataSet.WriteXml("C:\Temp\XMLData\OTHDISTQ.xml")
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial