Solved

Sorting IXMLDOMNodeList

Posted on 2008-11-03
4
1,639 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

719 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