Skip to main content
8-Gravel
September 1, 2021
Solved

ACL Single filepath data processing vs Batch Files Data processing logic

  • September 1, 2021
  • 1 reply
  • 4159 views

Currently I am able to execute a basic script to open a file, perform data processing, save then close.

 

For a batch process though, my thought process is to get the directory path filled with the collection of "*.xml" files, iterate over each file path and perform the functions doc_open, <functions to edit file>, doc_save, doc_close. 

 

However as the script iterates over the files it doesn't appear to be making any modications as anticipated, and in the file explorer there is no updated "Date Modified" timestamp confirming that changes have not been made.

I get the correct count of xml files stored in the variable $filepaths. When I perform a "message" or "response" command it appears to be the correct $filepath but not certain as it doesn't seem to get modified. the replace function always returns saying "string not found" even though I am certain of the strings existence in the file.

 

My question is: Where am I going wrong in the logic for ACL Batch File Processing. Is it correct to think I should be able to grab all file paths and just perform a doc_open like i would on a single file modification? And is it possible to "open as text" instead of with the options "schema/dtd" or "free form mode"? I feel as "open as text" may provide the most freedom in programmability but I could be wrong.

 

Unfortunately I can not install powershell, notepad++, alternative programming languages or any other softwares thus the arbortext editor and its built in languages must suffice. If there is a suggestion to stay with ACL or also try perlscript in the Epic Editor im happy to hear suggestions for the best approach using epic editor for batch process string manipulation. Java unfortunately won't work because I won't be able to compile in the command prompt due to lack of a JDK install capability.

 

Thank You!

 

 

$filesDirectoryPath = "C:/Users/MyDirectory/Desktop/source_xml/"
$isDirectory = file_directory($filesDirectoryPath)
global filepaths[]

$XMLFilesPath = $filesDirectoryPath . "/" . "*.xml"
glob($XMLFilesPath, $filePaths)
 
$filePathsCount = count($filePaths)

for ($i = 1; $i < $filePathsCount; $i++) { #acl 1 based array reason for start index
 $filePath = $filePaths[$i]

 $documentID = doc_open($filepath, 0x80002) 
 replace($string1, $string2', 0x2002, "", $documentID)
 doc_save($documentID)
 doc_close($documentID) 
}

# 0x80002 i believe will open the file for writing and in "free form mode", please correct me if im wrong. !!!I am also wondering if its possible to "open as text" but there does not seem to be that capability documented in "doc_open" help center!!!

#0x2002 I believe will replace all instances in the file and be case sensitive search. 

 

 

 

 

 

Best answer by GarethOakes

Ah, OK, you are opening XML files. You will have to force it to open the files in text mode, otherwise you must use the oid_xxx methods to manipulate the document as a structured tree (not as text). I don't have time to look into it right now but Arbortext usually does this if you use: edit -untagged myfilename.xml

1 reply

16-Pearl
September 2, 2021

The following code fragment works as I'd expect, open all text files and replace uppercase "T" with uppercase "X":

glob('C:\\test\\*.txt', $myArray)
for ($i = 1; $i <= count($myArray); $i++) {
 #DEBUGGING# response($myArray[$i])
 $docId = doc_open($myArray[$i])
 replace('T', 'X', 0x2002, '', $docId)
 doc_save($docId)
 doc_close($docId)
}
8-Gravel
September 2, 2021

Unfortunately no matter what I do with the provided response it is unsuccessful in opening up a folder full of XML files and successfully modifying each document and saving.

 

i've additionallly attempted to remove the ".xml" extension (using substr() combined with length()-4 (removing ".xml") to match the file name exactly without the extension. And again, if I perform the script on a single file and not in a loop it is successful. if the doc open, doc save, doc close are performed in a loop nothing occurs. Really banging my head on this one.

 

Also the replace function should also look into the "Entity" tags if that provides any additional info. Id like to perform edits on the whole file as a text file instead of just the value fields of a tag found in xml. I feel as if this may also be of significance. in the documentation for "doc_open" I only see that I can set the file to open programmatically as "free form mod". correct me if im wrong though! 

 

if I programmatically set it to free form mode nothing is accomplished. however if I manually select "open as text" when the document is loaded i believe it is successful. 

 

 

16-Pearl
September 2, 2021

Ah, OK, you are opening XML files. You will have to force it to open the files in text mode, otherwise you must use the oid_xxx methods to manipulate the document as a structured tree (not as text). I don't have time to look into it right now but Arbortext usually does this if you use: edit -untagged myfilename.xml