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

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Run ACL code for many documents

aneder
6-Contributor

Run ACL code for many documents

Hello adepters,



I have document with tag "sdc" - System Difference Code, which content is
"A". I need to change content of all instances of tag "sdc" from A to B.
I wrote simple code which produces such work.

But, I have hundreds or thousands documents with sdc=A. It is not reasonable
to make such work manually. I need to run my ACL code for many documents
from a list of files or for all documents in directory.

Does somebody knows, is it possibly to produce by ACL:



- open document (file name from a list of xml files)

- run ACL

- save and close document

- open next document from the list of files, and so on?



My code for reference for one document:



function sdca2b()

{

#

# Replace content of SDC elements from "A" to "B"

#

# find all SDC and put oids into array

#

$sdc_array = xpath_nodeset (sdc_nodes,"//sdc");

#

# Get markups SDC from array

#

for (i=1; i <= sdc_array.length; i++ )

{

goto_oid(sdc_nodes[i]);

if (oid_content(sdc_nodes[i]) == "A")

{

#

#mark and delete content of tag sdc

#

mark -noselect -noinvert begin;

goto_oid(sdc_nodes[i], -1);

mark end;

delete_mark;

# insert string "B"

is "B";

}

}



}



Thanks for all in advance,



Alexander Neder

+7 495 737 7878,

Department Manager,

PTS,

16, Marxistskya, Moscow, Russia.







3 REPLIES 3

Hi Alexander-



Sure, you can do this. Use the glob() function to get your list of
items, then iterate over it, something like this:



local $files[];

glob("*.xml",$files);



# untested code, debugging is left as an exercise

for ($file in $files) {

local $doc = doc_open($files[$file]);

current_doc($doc);

sdca2b();

doc_save($doc);

doc_close($doc);

}



HTH



--Clay




aneder
6-Contributor
(To:aneder)

Hello Clay,



Good! It does work!

The only problem was incorrect quotes in glob("*.xml",$files) - probably
mail client repairs them.



Thank you very much!



Final code is:



function all_files()

{

local $files[];



if (file_directory("C:/work/mydoc") == 1)

{eval "c/work/mydoc is a directory" output=>*}



glob("C:/work/mydoc/*.xml",$files);



# untested code, debugging is left as an exercise

for ($file in $files)

{

local $doc = doc_open($files[$file]);

current_doc($doc);

sdca2b();

doc_save($doc);

doc_close($doc);

}

}



function sdca2b()

{

#

# Replace content of SDC elements from "A" to "B"

#

$sdc_array = xpath_nodeset (sdc_nodes,"//sdc");

#

# Get markups SDC from array

#

for (i=1; i <= sdc_array.length; i++ )

{

goto_oid(sdc_nodes[i]);

if (oid_content(sdc_nodes[i]) == "A")

{

mark -noselect -noinvert begin;

goto_oid(sdc_nodes[i], -1);

mark end;

delete_mark;

is "B";

}

}



}



Sincerely,



Alexander Neder

+7 495 737 7878,

Department Manager,

PTS,

16, Marxistskya, Moscow, Russia.







_____

Hi Alexander-



Great, glad it works for you. Now that you've tested it, you can take
out the comment about it being untested code. 🙂



--Clay


Top Tags