?
Solved

Sorting IXMLDOMNodeList

Posted on 2008-11-03
4
Medium Priority
?
1,672 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 750 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

801 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