I'm so frustrated on this one. I use this function on another XML tag group and it works fine. The only thing I've changed is the starting tag string. So what this script is supposed to do. It selects the <emergproccl> to end tag </emergproccl>. Then spilts the found tags by end procedure tag </procedure> and creates new file for each </procedure>. Each new file has some other functions it performs, but that's not what's important. I need to understand why the <emergproccl> to </emergproccle> tags aren't splitting. Files attached. Thank you for the help.
Test javascript
Test SGM:
Test javascript
Code: Select all
var eSplitString = "</procedure>";
// String where to split. The split occurs after next character.
filePath = 'C:\\Test\\Bursting Documents\\TEST';
// Path to put spliced files in
//filePath = UltraEdit.getString("Directory to place files in", 1);
//Append a backslash if it is missing at end of the directory string.
if (filePath.match(/\\$/) === null) filePath += "\\";
//UniqID = UltraEdit.getString("Enter a UNIQUE ID for this manual", 1);
UniqID = "TEST";
function emergproccl() {
if (UltraEdit.document.length) { // Is any file open?
// Set working environment required for this job.
UltraEdit.insertMode();
if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
UltraEdit.activeDocument.hexOff();
UltraEdit.perlReOn();
// Move cursor to top of active file and run the initial search.
UltraEdit.activeDocument.top();
UltraEdit.activeDocument.findReplace.searchDown=true;
UltraEdit.activeDocument.findReplace.matchCase=false;
UltraEdit.activeDocument.findReplace.matchWord=false;
UltraEdit.activeDocument.findReplace.regExp=true;
UltraEdit.activeDocument.top();
// Select everything in parent elements
if (UltraEdit.activeDocument.findReplace.find('<emergproccl')) {
var nLine1 = UltraEdit.activeDocument.currentLineNum;
var nColumn1 = UltraEdit.activeDocument.currentColumnNum - 15;
UltraEdit.activeDocument.findReplace.regExp = true;
if (UltraEdit.activeDocument.findReplace.find("<\/emergproccl>")) {
UltraEdit.activeDocument.key("RIGHT ARROW");
if (UltraEdit.activeDocument.isSel()) {
// All the emergproccl elements are selectef from start tag to end tag.
UltraEdit.outputWindow.write("Inside Sel");
UltraEdit.activeDocument.gotoLine(0, UltraEdit.activeDocument.currentColumnNum - 15);
}
UltraEdit.activeDocument.gotoLineSelect(nLine1, nColumn1);
}
var emergproc = UltraEdit.activeDocument.selection;
Regex = /(<emergproccl.*?>)(\r?\n)?<title>(.*?)<\/title>/i;
match = Regex.exec(emergproc);
if (match !== null) {
// Get emergproc starting tag and title tags
emergprocFullTag = match[0];
UltraEdit.outputWindow.write("emergprocFullTag " + emergprocFullTag);
// Get just the title
emergprocSTitle = match[3];
UltraEdit.outputWindow.write("emergprocSTitle " + emergprocSTitle);
if (emergprocSTitle !== "") {
// legend.push(["\t" + emergprocSTitle]);
}
}
// Get the emergproc content as array of strings with splitting the
// file on each occurrence of end tag of XML element procedure.
var asProcedures = emergproc.split("</procedure>");
if (!asProcedures)
{
UltraEdit.activeDocument.top();
}
// The last string in array must be always ignored.
var nProcedureCount = asProcedures.length - 1;
UltraEdit.outputWindow.write("Emerg Proc Count: " + nProcedureCount);
}
// If the string to split is not found in this file, do nothing.
if (UltraEdit.activeDocument.findReplace.find(eSplitString)) {
UltraEdit.outputWindow.write("Inside eSplitString");
var FileNumber = 1; // Counts the number of saved files.
var StringsFound = 1; // Counts the number of found split strings.
var NewFileIndex = UltraEdit.document.length;
/* Get active file index in case of more than 1 file is open and the
current file does not get back the focus after closing the new files. */
var FileToSplit = getActiveDocumentIndex();
// Always use clipboard 9 for this script and not the Windows clipboard.
UltraEdit.selectClipboard(9);
// Split the file after every x found split strings until source file is empty.
while (1) {
while (StringsFound < FoundsPerFile) {
if (UltraEdit.document[FileToSplit].findReplace.find("</procedure>")) StringsFound++;
else {
UltraEdit.document[FileToSplit].bottom();
break;
}
}
// End the selection of the find command.
UltraEdit.document[FileToSplit].endSelect();
// Move the cursor right to include the next character and unselect the found string.
UltraEdit.document[FileToSplit].key("RIGHT ARROW");
// Select from this cursor position everything to top of the file.
UltraEdit.document[FileToSplit].selectToTop();
// Is the file not already empty?
if (UltraEdit.document[FileToSplit].isSel()) {
// Cut the selection and paste it into a new file.
UltraEdit.document[FileToSplit].cut();
UltraEdit.newFile();
fileNum++;
UltraEdit.document[NewFileIndex].setActive();
setDTD();
// UltraEdit.activeDocument.write(placeHolderFront7900);
// UltraEdit.activeDocument.write(placeHolderNormproc7900);
UltraEdit.activeDocument.write(emergprocFullTag);
UltraEdit.activeDocument.paste();
titleStr = UniqID + "_" + fileNum;
UltraEdit.saveAs(filePath + titleStr + ".sgm");
fileNo.push("&" + titleStr + ";");
debug.write("File created: " + titleStr + ".sgm ");
StringsFound = 0;
UltraEdit.closeFile(UltraEdit.activeDocument.path, 2);
/* Delete the line termination in the source file
if last found split string was at end of a line. */
UltraEdit.document[FileToSplit].endSelect();
UltraEdit.document[FileToSplit].key("END");
if (UltraEdit.document[FileToSplit].isColNumGt(1)) {
UltraEdit.document[FileToSplit].top();
} else {
UltraEdit.document[FileToSplit].deleteLine();
}
} else break;
} // Loop executed until source file is empty!
// Close source file without saving and re-open it.
var NameOfFileToSplitE = UltraEdit.document[FileToSplit].path;
UltraEdit.closeFile(NameOfFileToSplitE,2);
/* The following code line could be commented if the source
file is not needed anymore for further actions. */
UltraEdit.open(NameOfFileToSplitE);
// Free memory and switch back to Windows clipboard.
UltraEdit.clearClipboard();
UltraEdit.selectClipboard(0);
}
}
}
emergproccl();
Code: Select all
<doc>
<emergproccl>
<title>YECURG DORMPEEEERSNC</title>
<secttoc autobuild="1">
<procedure emergency="0" verstatus="ver" newpage="1">
<title>ATOBR</title>
<clstep1 verstatus="ver">
<clitem>
<emphasis type="b">HTROLTTE</emphasis>
</clitem>
<action>
<emphasis type="b">fsur eevlerl</emphasis>
</action>
<cpos>P</cpos>
</clstep1>
<clstep1 verstatus="ver">
<clitem>
<emphasis type="b">ERKSBA</emphasis>
</clitem>
<action>
<emphasis type="b">pplay</emphasis>
</action>
<cpos>P</cpos>
<symbs>
<symb>C</symb>
</symbs>
</clstep1>
<condition>CFD PPTRD EFP:ATIE ERALRAH RIA WFLS TERUIERAC</condition>
<clstep1 verstatus="ver">
<clitem>oe Cdnnotrlviie</clitem>
<action>aft</action>
<cpos>P</cpos>
<symbs>
<symb>C</symb>
</symbs>
</clstep1>
<clstep1 verstatus="ver">
<clitem>CigS nGioint</clitem>
<action>oCdl</action>
<cpos>P</cpos>
</clstep1>
<end>
</procedure>
<procedure emergency="0" verstatus="ver" newpage="1">
<title>IIL TEAFUF RRUNGLKLODTAOER IEFR</title>
<condition>TNIS I FDOS OCEIOPT SIM :DAE</condition>
<clstep1 verstatus="ver">
<clitem>otrbA</clitem>
<action>rpefrmo</action>
<cpos>P</cpos>
</clstep1>
<condition>DIAS EF CIED:NMOISIOCT OEUNN ITOFTF KEA</condition>
<clstep1 verstatus="ver">
<clitem>deninL graag</clitem>
<action>otd nctotar er</action>
<cpos>P</cpos>
</clstep1>
<clstep1 verstatus="ver">
<clitem>alFps</clitem>
<action>ras reqdeiu</action>
<cpos>P</cpos>
<symbs>
<symb>C</symb>
</symbs>
</clstep1>
<clstep1 verstatus="ver">
<clitem>gasdit Linn hitWA hciFkletle craT </clitem>
<action>ltocepem</action>
<cpos>P</cpos>
</clstep1>
<end>
</procedure>
<procedure emergency="0" verstatus="ver" newpage="1">
<title>UAKRIFER OEGD O IRTNFENOIGELA E FRRLNO EVTH</title>
<condition> SECDIIFI DEPMION: TAO SSOT</condition>
<clstep1 verstatus="ver">
<clitem>tboAr</clitem>
<action>ferpomr</action>
<cpos>P</cpos>
</clstep1>
<condition>S MIFIAN DUDSEEI:CIOONTFN E OTCATOIFKE</condition>
<clstep1 verstatus="ver">
<clitem>Cmlib</clitem>
<action>ltaoietut fad se</action>
<cpos>P</cpos>
</clstep1>
<clstep1 verstatus="ver">
<clitem>ottlhreT</clitem>
<action>eitqaaflrds ieu tuaeto rea diatt/tmninaas in</action>
<cpos>P</cpos>
</clstep1>
<condition>SSAT OEOIIRRETT RKI.CNDECSRILEI GTFRERR,GFSEEEHIEN EED IKOINLEN ECANDINHVG AU A NRCHQE CTCHFDKEO LVW CREEL</condition>
<clstep1 verstatus="ver">
<clitem>raftircA</clitem>
<action>n snbipoelosossaa s ald</action>
<cpos>P</cpos>
</clstep1>
<end>
</procedure>
<procedure emergency="0" verstatus="ver" newpage="1">
<title>GAELRAGWLN NIID C NTOATLR RET</title>
<clstep1 verstatus="ver">
<clitem>isariot nGpoe</clitem>
<action>frVyie</action>
<cpos>SO</cpos>
</clstep1>
<condition>ENTMOASD LSLGTI T /. L ETN I,T CALEEPFDRE I,ALH CRHCRGYCC ETOESRTEHXAHAIU WF FIRECKNE EO UWS3TPCHLNKHOL TE SS O4L RIA RD HWLWNATTFEIHS NSTODHTSF EID OTNWEAGENHI HEAN IAIDG</condition>
<condition>GNEIH E IME3 AOEPTNW XTGT FLEOHR LA 4NWO AEDD /RENTRAICI:FA NELSHSOT R NS AWHTDH EFR FEITN OH OKI A IOSTITCNC</condition>
<clstep1 verstatus="ver">
<clitem>raeG</clitem>
<action>dnwo</action>
<cpos>P</cpos>
</clstep1>
<clstep1 verstatus="ver">
<clitem>ratfircA</clitem>
<action>saosoactinp rasc aladl n</action>
<cpos>P</cpos>
</clstep1>
<condition>NGDFTFIFEH LEOCESLNKA LI E DRNUTOTL. FN L E ILXIEGCESROY ERAITDWRLEOE X, DNA TA INGDETR</condition>
<end>
</procedure>
<procedure emergency="0" verstatus="ver" newpage="1">
<title> EENGDCNUFNYET HNR AGRIED MREO OPI/</title>
<symbs>
<symb>W</symb>
</symbs>
<clstep1 verstatus="ver">
<clitem>
<emphasis type="b">NIENOCLT ORDEIV</emphasis>
</clitem>
<action>
<emphasis type="b">fat</emphasis>
</action>
<cpos>P</cpos>
</clstep1>
<clstep1 verstatus="ver">
<clitem>GET</clitem>
<action>omceodreasnt eir</action>
<cpos>P</cpos>
</clstep1>
<clstep1 verstatus="ver">
<clitem>PMR</clitem>
<action>o rsedctreoMeian</action>
<cpos>P</cpos>
</clstep1>
<clstep1 verstatus="ver">
<clitem>GgCniiotSn i</clitem>
<action>docl</action>
<cpos>P</cpos>
</clstep1>
<clstep1 verstatus="ver">
<clitem>retEccilalla od</clitem>
<action>ceedru</action>
<cpos>S O,P</cpos>
<clstep2 verstatus="ver">
<clitem> lL SnARxyca prt nleoopneorw</clitem>
<action>fof</action>
<cpos> ;OdPnS hsa&</cpos>
</clstep2>
<clstep2 verstatus="ver">
<clitem>iAd rmobmroneep ewor</clitem>
<action>roaqeufiesr d,f </action>
<cpos>P</cpos>
</clstep2>
<clstep2 verstatus="ver">
<clitem>adaPlyo</clitem>
<action> saueqerird</action>
<cpos>OS</cpos>
</clstep2>
<clstep2 verstatus="ver">
<clitem>aN rvntbh ittiangosieaols gd</clitem>
<action>ffo</action>
<cpos>P</cpos>
</clstep2>
<clstep2 verstatus="ver">
<clitem>rodtneFFsI ranp</clitem>
<action>off</action>
<cpos>SP & nd;aOsh</cpos>
</clstep2>
<clstep2 verstatus="ver">
<clitem> UoARACVr-dai102 </clitem>
<action>foffi o n,qt uerierd</action>
<cpos>n;Odhs P S&a</cpos>
</clstep2>
<clstep2 verstatus="ver">
<clitem>eoatPtht i</clitem>
<action>sa reuiqedr</action>
<cpos>P</cpos>
</clstep2>
<clstep2 verstatus="ver">
<clitem>ehru tFleea</clitem>
<action>f a ,osfdeueirqr</action>
<cpos>P</cpos>
<symbs>
<symb>C</symb>
</symbs>
</clstep2>
<clstep2 verstatus="ver">
<clitem>proMweC M</clitem>
<action>q oua, refdfseir</action>
<cpos>P</cpos>
</clstep2>
<!--modified text from "SMS power" per FM scrub. KK 4/08/15-->
<clstep2 verstatus="ver">
<clitem>asInR ee leesNhrto</clitem>
<action>off</action>
<cpos>P</cpos>
</clstep2>
<clstep2 verstatus="ver">
<clitem>sNeh s eatolen</clitem>
<action>%0</action>
<cpos>P</cpos>
</clstep2>
</clstep1>
<condition>STIPCATF NHRWH OREEECEINATCG OCKDLII HER TNSSERF AINFST ISAOFNPTMN.EMPSOT NUE GLIAD DP,LNDD EARTTO ACI</condition>
<end>
</procedure>
<procedure emergency="0" id="mq9_p0001" verstatus="ver" newpage="1">
<title>EFNNGEI LUIEAR</title>
<clstep1 verstatus="ver">
<clitem>
<emphasis type="b">ELGDI</emphasis>
</clitem>
<action>
<emphasis type="b">tseshbail</emphasis>
</action>
<cpos>P</cpos>
</clstep1>
<clstep1 verstatus="ver">
<clitem>
<emphasis type="b">NILEI SGANTD</emphasis>
</clitem>
<action>
<emphasis type="b">cleets</emphasis>
</action>
<cpos>P</cpos>
<symbs>
<symb>W</symb>
</symbs>
<symbs>
<symb>C</symb>
</symbs>
</clstep1>
<clstep1 verstatus="ver">
<clitem>
<emphasis type="b">NLODINIT OECERV</emphasis>
</clitem>
<action>
<emphasis type="b">a,tfs aqirdreue</emphasis>
</action>
<cpos>P</cpos>
<symbs>
<symb>C</symb>
</symbs>
</clstep1>
<condition>ITEFTMITTITTSPO REIAMS NRT ( PMETNANDOCO IFE,TDARE ER R<xref xrefid="EArestart"> CEHICKLS.)T</condition>
<condition>R NIS I SORFTIE P TEOOTLRASI SBS U,NSSCUUCFSELP AOR EERCPRFFOE RGNN.D ALDI</condition>
<clstep1 verstatus="ver">
<clitem>ticcreEllal aod</clitem>
<action>rudece</action>
<cpos>SP, O</cpos>
<symbs>
<symb>C</symb>
</symbs>
<clstep2 verstatus="ver">
<clitem>nprpowlocLnn ero S eAaRylxt</clitem>
<action>ffo</action>
<cpos>Ssd P;O &han</cpos>
</clstep2>
<clstep2 verstatus="ver">
<clitem>eoiwrrbArone modme p</clitem>
<action>qef efrui,orda s</action>
<cpos>P</cpos>
</clstep2>
<clstep2 verstatus="ver">
<clitem>oaydPal</clitem>
<action>reas rieqdu</action>
<cpos>OS</cpos>
</clstep2>
<clstep2 verstatus="ver">
<clitem>vNoai atrignoabeit sn lsdhgt</clitem>
<action>ffo</action>
<cpos>P</cpos>
</clstep2>
<clstep2 verstatus="ver">
<clitem> aFFInrtsponred</clitem>
<action>fof</action>
<cpos>dShs ;aO& Pn</cpos>
</clstep2>
<clstep2 verstatus="ver">
<clitem>Vi-AU2r0o a1dRCA</clitem>
<action>ir de,ffoif n otrequ</action>
<cpos>O Ss Pd;anh&</cpos>
</clstep2>
<clstep2 verstatus="ver">
<clitem>ae toitPth</clitem>
<action>ed rearqius</action>
<cpos>P</cpos>
</clstep2>
<clstep2 verstatus="ver">
<clitem>eFehul aetr</clitem>
<action> faso ,ferquried</action>
<cpos>P</cpos>
<symbs>
<symb>C</symb>
</symbs>
</clstep2>
<clstep2 verstatus="ver">
<clitem>MCMrow ep</clitem>
<action>uf,r iefoq reasd</action>
<cpos>P</cpos>
</clstep2>
<clstep2 verstatus="ver">
<clitem> etsoh INa Reesln</clitem>
<action>fof</action>
<cpos>P</cpos>
</clstep2>
<clstep2 verstatus="ver">
<clitem>oNelse nh seat</clitem>
<action>%0</action>
<cpos>P</cpos>
</clstep2>
</clstep1>
<clstep1 verstatus="ver">
<clitem>aBaptptlc erytiaoi inmte</clitem>
<action>tiomonr</action>
<cpos> SP,O</cpos>
</clstep1>
<clstep1 verstatus="ver">
<clitem>t yetarBevgalto</clitem>
<action>oMtroni</action>
<cpos> SP,O</cpos>
<symbs>
<symb>C</symb>
</symbs>
</clstep1>
<clstep1 verstatus="ver">
<clitem> nelivCtnredoio</clitem>
<action>qf ,aerut ardsei</action>
<cpos>P</cpos>
<symbs>
<symb>C</symb>
</symbs>
</clstep1>
<clstep1 verstatus="ver">
<clitem>r eu odKuxlteeilpvim</clitem>
<action>udidn,tgosapiir z eq rmlnea eorfi</action>
<cpos>S,P O</cpos>
</clstep1>
<clstep1 verstatus="ver">
<clitem>erGa</clitem>
<action>dsdo aq wner,iuer</action>
<cpos>P
</cpos>
<symbs>
<symb>C</symb>
</symbs>
</clstep1>
<condition>VIREWEF ORCEL DAHETCGKN SDCNII LAN D<xref xrefid="SATCOMland">SS, STCHAELICKDQREIREU.</condition>
<end>
</procedure>
</emergproccl>
</doc>
- ProcSplitErrors.zip (4.77 KiB) 0
- javascript and sgm file.