cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

ACL Single filepath data processing vs Batch Files Data processing logic

ED_9927023
7-Bedrock

ACL Single filepath data processing vs Batch Files Data processing logic

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. 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

4 REPLIES 4

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)
}

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. 

 

 

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

"edit" command with "-untagged" argument set solved my problem. It did take a while to understand how ACL works with arguments in Functions vice Commands. For the longest time I couldn't understand why my variable was essentially not existing when being passed into an ACL command.

 

so the complete solution for me is: 

 

execute("edit -untagged " . $filePath)

execute("save_as -xml " . $newFilePath)

 

and this is due to variables getting set and existing at runtime but not at compilation. This is the aspect which acted as a roadblock as I could see the filenames print to the screen in a "response()" ACL FUNCTION but not being used in an ACL COMMAND

 

Top Tags