Dear P.O., thank you for all of your efforts and work which allowed me to quickly find the reason for spurious additional blank lines!
The reason is that there are quite a few programlisting elements with a CDATA-section content which the script has not tackled so far. So here an adjusted version of the script that processes CDATA sections as well: ---rgf, 2020-02-02, 2020-02-22: strip CR-LF from ooRexx xml program listings start=.dateTime~new call sysfiletree "*.xml", "files.", "FOS" end =.dateTime~new say "SysFileTree duration:" end-start", about to process" files.0 "files" len=files.0~length do i=1 to files.0 say i~right(len)":" files.i call stripBlankLines files.i end end =.dateTime~new say "processed" .count~counter "<programlisting> elements, duration:" end-start ::routine stripBlankLines parse arg fileName inStr=.stream~new(fileName)~~open("read") chars=inStr~chars allChars=inStr~charin(1,chars) inStr~close startNeedle="<programlisting>" endNeedle ="</programlisting>" cdataStart ="<![CDATA[" cdataEnd ="]]>" crlf ="0d0a"x mbOut=.mutableBuffer~new(,chars) bEdited=.false do while allChars<>"" parse var allChars before (startNeedle) program (endNeedle) allChars if program="" then do if allChars="" then -- arrived at end of file mbOut~append(before) else -- maybe a placeholder of whitespace do mbOut~append(before, startNeedle, program, endNeedle) .count~increase end end else -- strip leading and trailing CR-LF characters do -- check for CDATA-section, remove leading trailing blank lines there as well if program~pos(cdataStart)>0 then do parse var program (cdataStart) program (cdataEnd) mbOut~append(before, startNeedle, cdataStart, program~strip("both",crlf), cdataEnd, endNeedle) end else do mbOut~append(before, startNeedle, program~strip("both",crlf), endNeedle) end .count~increase bEdited=.true end end -- write new file, if strip changes took place if bEdited then .stream~new(fileName)~~open("write replace")~~charout(mbOut~string)~close ::class count ::attribute counter class ::method init class expose counter counter=0 ::method increase class expose counter counter+=1 Cheers, ---rony
_______________________________________________ Oorexx-devel mailing list Oorexx-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/oorexx-devel