Skip to main content
1-Visitor
August 26, 2010
Question

Run ACL code for many documents

  • August 26, 2010
  • 3 replies
  • 1152 views
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

    18-Opal
    August 26, 2010
    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




    aneder1-VisitorAuthor
    1-Visitor
    August 27, 2010
    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.







    _____
    18-Opal
    August 27, 2010
    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