how to sort XML record ?

tyhau

New member
Joined
Feb 20, 2008
Messages
3
Programming Experience
Beginner
Hi,I'm newbie here.I face some problem about my project.Hope that you all who know it can help me.
I want to sort the list of the nodes that depand on which element nodes that user wish to sort.

For example:Below is my XML data
HTML:
<RegistrationRecord>
  <tblRegistration>
     <company_name>ABC Sdn Bhd</company_name>
     <non_expiry>Evalution</non_expiry>
     <expiry_date>23-Jun-2006</expiry_date>
     <admin_module>Process Manager</admin_module>
     <scan_module>Workgroup</scan_module>
     <web_module>Process Manager (Content Search)</web_module>
     <date_created>18-Jun-2006</date_created>
     <user_name>Manager</user_name>
</tblRegistration>

<tblRegistration>
   <company_name>XYZ Sdn Bhd</company_name>
      <non_expiry>Permenent</non_expiry>
      <expiry_date></expiry_date>
      <admin_module>Basic</admin_module>
      <scan_module>Non-Scan</scan_module>
      <web_module>Version Control (Content Search)</web_module>
      <date_created>27-Apr-2006</date_created>
      <user_name>SysAdmin</user_name>
</tblRegistration>
</RegistrationRecord>
-->I already complete the retrive XML data function,and my data output is show as table form.It work.
-->And now i want to add the sort function to sort my XML data.But i don't know how to started.

-->If user want to sort the company_name element,then after clicking the sort command button only the whole company_name element table column will be sort at that column. In the other way,if user want to sort the user_name element,then after clicking the sort command button only the whole user_name element table column will be sort at that column.

-->Can you provide me some source code about this that can show the sample sorting by using the above XML example??

Thanks in advance.
 
Last edited by a moderator:
You can do this both by setting the Sort property of the tables DefaultView, or using the Sort method on the DataGridView.
VB.NET:
Dim ds As New DataSet
ds.ReadXml("yourdata.xml")
Me.DataGridView2.DataSource = ds.Tables(0)
Me.DataGridView2.Sort(Me.DataGridView2.Columns("company_name"), ListSortDirection.Descending)
' or:
' ds.Tables(0).DefaultView.Sort = "company_name DESC"
 
continue Sorting XML record problem using vb.net..please help.

Hi Sir,

I still face a problem about XML sorting.
I'm using vb.net code to create my table,not using data GridView to view
my table.

My vb.net table code is like that:

VB.NET:
'create the table column
Dim strTable As String
strTable += "<th>Company Name</th>"
        strTable += "<th>Scan module</th>"
        strTable += "<th>web module</th>"
        strTable += "<th>User name</th>"
  strTable += "</tr>"

If Not (nodes Is Nothing) And nodes.Count > 0 Then
            Dim intcount As Integer = 1
            Dim oStringBuilder1 As New StringBuilder()
            Dim oStringBuilder2 As New StringBuilder()
            Dim oStringBuilder3 As New StringBuilder()
            Dim oStringBuilder4 As New StringBuilder()

'Loop the XML record that match the criteria
Dim oNode As XmlNode
For Each oNode In nodes
  strTable += "<tr><td>" & intcount & "</td>"
  strTable += "<td>" & oNode.ParentNode.ChildNodes(1).InnerText & "</td>"
  strTable += "<td>" & oNode.ParentNode.ChildNodes(2).InnerText & "</td>"
  strTable += "<td>" & oNode.ParentNode.ChildNodes(3).InnerText & "</td>"
  strTable += "<td>" & oNode.ParentNode.ChildNodes(4).InnerText & "</td>"
  strTable += "</tr>"
  intcount += 1
  Next
   'show the xml record on table form
   lbltable.Text = strTable

Else

   lbltable.Text = "No Record Found!"

End If

--> i want sort the XML record after i view the XML record in table form.
-->for example: when i want to sort the company name,then i choose the company name in drop down list(ddlsort),after i clicking sort command button(cmdSort),only the company name column will be sort by ascending.

-->How to make it be possible??
please help.Thanks.

By tyhau
 
So are you asking about ASP.NET actually?
 
continue Sorting XML record problem using vb.net..please help.

So are you asking about ASP.NET actually?

HI Sir,
Actually i'm not asking about ASP.NET.I'm asking about vb.net and XML combination.
I use visual studio 2005 to create my project.My project output is a web form that can view the XML data by criteria child element and sort the XML data by ascending.
My question is how to Sort the XML Record by ascending after viewing the XML data.I already complete the viewing part and it work,and now i don't know how to Sort it.And i'm not using data gridview to view my XML data.
SO,can you please show me the sample source code or any other useful guide about SORT XML record using vb.net??

Thanks.
 
Webforms is ASP.NET, with which you can program in VB.Net/C# and such languages. Read about the Xml server control, read about XSLT, with this you can create a sorted display dynamically in web page. Most likely the GridView control can be used too.
 
Back
Top