Solved

Sorting IXMLDOMNodeList

Posted on 2008-11-03
4
1,576 Views
Last Modified: 2009-03-24
I have an Nodelist that i want to read in to an Excelsheet, but first i want to sort the list by 1.ProjectId or Name, 2. by AssignmentID?
Dim AssignmentsNode As IXMLDOMNodeList
Dim AssignmentNode As IXMLDOMNode
 
Set oXMLDAssignments = New DOMDocument30
oXMLDAssignments.loadXML (XML)
        
If oXMLDAssignments.parseError.errorCode = 0 Then
   If Not oXMLDAssignments Is Nothing Then
     Set AssignmentsNode = oXMLDAssignments.selectNodes("//Assignment")
   End if
end if
 
How can i sort the assignmentsNode (IXMLDOMNodeList)  by "ProjectID" or "ProjecName" and "Assignment" before 
 
 
For Each AssignmentNode In AssignmentsNode
  Get assignmentdata 
Next
 
Result:
Project1
  Assignment1
  Assignment2...
Project2
  Assignment1
  Assignment2...

Open in new window

0
Comment
Question by:Torsleff-Experten
  • 2
4 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 22866094
Check this:
AssignmentsNode.SortRecordsByContent("Assignment", True)
AssignmentsNode.SortRecordsByContent("ProjectID", True)

Open in new window

0
 
LVL 27

Expert Comment

by:BigRat
ID: 22866098
There is no method in NodeList to sort the elements, and probably trying to write one will take a lot of time. THere is however a solution using XSL which produces the document sorted as you want. It runs like :-

XMLDoc.Load sXMLFile
XSLDoc.Load sortXSLFile
XMLDoc.loadXML(XMLDoc .transformNode(XSLDoc));

Hereafter you select the top level nodes you want.

sortXSLFile
----------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

 <xsl:template match="/toplevel">
  <xsl:copy>
   <xsl:apply-templates select="/leveltosort" />
    <xsl:sort select="sortColumn" data-type="number" order="ascending"/>
   </xsl:apply-templates>
  </xsl:copy>
 </xsl:template>

</xsl:stylesheet>

Here column to sort is numeric. See XSLT Sort element for further options.
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 250 total points
ID: 22866629
Sorry, DOMDocument30 has no SortRecordsByContent() method.
0
 
LVL 2

Author Comment

by:Torsleff-Experten
ID: 22866700
hmm yes i came to that conclusion too, could i use a XSL stylesheet or some other way?

i have tried sorting the data after i put it to Excel, but im getting this error:

1004 Method 'Range' of object '_Global' failed
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question