Loading ...
Sorry, an error occurred while loading the content.

15735Sorting XML data

Expand Messages
  • Evert Everts
    Nov 3 4:20 PM
    • 0 Attachment
      I wrote a script for a job that the XML-editors I now could not fix:
      sorting XML-nodes in a simple structure. Sure there can a lot be done
      to make the script better, and with a big file it takes a long, long
      time to sort all the data, but it works...
      Insert the text below after 'Tools - Clipbook - Open Library'.

      ^!SetListDelimiter ##


      ^!Set %MaxRow%=^%database0%
      ^!Set %Row%=0; %Sort1%=^?[(2)Sort on=country]; %Sort2%=^?[(4)Sort 2 on
      (can be left blank)=email|surname]; %Sort3%=^?[(6)Sort 3 on (can be
      left blank)]

      ^!Inc %Row%
      ^!If ^%Row% > ^%MaxRow% EndLoop
      ^!SetHintInfo Processing... ^%Row% of ^%MaxRow% (Press Ctrl+Alt to stop)
      ^!Set %Rw%=^%Row%

      ^!Set %Sort%=^%Sort1%
      ^!Set %Znrow%=^$Findnode(^%Row%)$
      ^!Inc %Rw%
      ^!If ^%Rw% > ^%MaxRow% LoopStart
      ^!Set %Znrw%=^$Findnode(^%Rw%)$
      ^!If "^%Znrow%" ^?[(3)Order==_Ascending^=>|Descending^=<] "^%Znrw%"
      Next Else Checklevel2
      ^!Set %swap%=^%database^%Row%%
      ^!Set %database^%Row%%=^%database^%Rw%%
      ^!Set %database^%Rw%%=^%swap%
      ^!GoTo Loop2Strt
      ^!IfDiff "^%Znrow%" "^%Znrw%" Loop2Strt
      ^!IfSame "^%Sort2%" "^%empty%" Loop2Strt
      ^!Set %Sort%=^%Sort2%
      ^!Set %Znrow%=^$Findnode(^%Row%)$; %Znrw%=^$Findnode(^%Rw%)$
      ^!If "^%Znrow%" ^?[(5)Order 2==_Ascending^=>|Descending^=<] "^%Znrw%"
      Next Else Checklevel3
      ^!Set %swap%=^%database^%Row%%
      ^!Set %database^%Row%%=^%database^%Rw%%
      ^!Set %database^%Rw%%=^%swap%
      ^!GoTo Loop2Start
      ^!IfDiff "^%Znrow%" "^%Znrw%" Loop2Start
      ^!IfSame "^%Sort3%" "^%empty%" Loop2Start
      ^!Set %Sort%=^%Sort3%
      ^!Set %Znrow%=^$Findnode(^%Row%)$; %Znrw%=^$Findnode(^%Rw%)$
      ^!If "^%Znrow%" ^?[(7)Order 3==_Ascending^=>|Descending^=<] "^%Znrw%"
      Next Else Loop2Start
      ^!Set %swap%=^%database^%Row%%
      ^!Set %database^%Row%%=^%database^%Rw%%
      ^!Set %database^%Rw%%=^%swap%
      ^!GoTo Loop2Start

      ^!GoTo LoopStart

      ^!ToolBar New Document

      ^!InsertText ^$StrReplace("##";"^%NL%";"^%database%";No;No)$
      ^!Prompt "Insert the text in this New Document between the correct
      tags in the former document."

      ^!Set %S2%=^$StrPos("</^%Sort%>";"^%database^&%";Yes)$
      ^!Set %result%=^$StrCopy("^%database^&%";^%S1%;^$Calc(^%S2%-^%S1%)$)$