# Using the firstobject XML editor from the command line

The free firstobject XML editor has some command line switches. Here is the summary; details are below.

SwitchPurpose
-newopen in a new instance of the editor (useful when single instance preference is selected)
-sameopen in the existing instance of the editor
-watch "C:\event.log"open file in read-only auto-reloading mode to view the tail of log files
-line 23open file at a line
-offset 451UTF-8 offset from beginning of document or from beginning of line if line is specified
-fromoffset 5pre-select text from this offset to specified offset
-run script.foal:f arg1 arg2execute the script without showing the editor

Examples:

foxe.exe "C:\XML examples\file.xml" -line 6
foxe.exe file.xml -line 6 -offset 5
foxe.exe -offset 240 -fromoffset 235 file.xml
foxe.exe -watch C:\event.log
foxe.exe -run C:\script.foal
foxe.exe -same file.xml
"C:\Program Files\firstobject\foxe.exe" -new file.xml

How to run script automatically

Angela Baines 18-Jan-2010

The foal script works a treat now. When I move this to production it has to run as part of an automated project that will be scheduled to run overnight

As of release 2.4.1 the free firstobject XML editor has a command line switch to run a script:

foxe -run "C:\foal scripts\script.foal"

It generates 2 files, foxe_err.txt and foxe_out.txt. The err file contains marked up information about the run and can help diagnose issues with running. The out file contains the output returned from the script in the return statement.

And with release 2.4.2 you can specify function and arguments, see below.

Run from command line problem

Garth Lancaster 19-Jul-2010

In foxe I can do this [with a foal script]

str NavigateIterativelyXYZ_Generated( CMarkup mDocToNavigate )
{
mDocToNavigate.ResetPos();
str sXML = mDocToNavigate.GetDocFormatted(0);
return sXML;
}

so when I run it, a window pops up and asks which document I wish to convert, shows me the output, all is good... except now, I wish to do this from a command line.

foxe –run align0.foal input.xml output.xml

Where align0.foal contains the foal program, input and output names will likely come from a batch script % parameter or such, and input.xml will contain the streamed xml and output.xml will contain the results of the GetDocFormatted(0). I'm thinking foal can be very powerful, am I missing a point in its implementation?

Update April 23, 2011: With release 2.4.2, it works the way it should (the way Garth described). The -run command line option passes any number of command line arguments into the parameters of the function in the foal script. For example (remember to use quotes if a path or argument contains spaces):

foxe -run "C:\foal scripts\script.foal" C:\in.xml C:\out.xml

Here is a script to format XML that works with the previous command line:

formatxml(str sInPath, str sOutPath)
{
CMarkup m, r;
if ( ! m.SetDoc(m.GetDocFormatted()) )
m.Save(sOutPath);
return r;
}

Bascially this script just loads the input file, calls GetDocFormatted and saves to the output file (you could also add an argument to pass format flags). In addition it returns the results in case something goes awry you can see what happened in foxe_out.txt. If there is no problem, it might look like this:

<load>C:\in.xml</load>
<save>C:\out.xml</save>
<write encoding="UTF-8" length="29958"/>


If there are multiple functions in a script, you can name your entry function main to avoid confusion about which function is being called. You can also specify the entry function explicitly on the command line with :function at the end of the script filename. Specifying the function allows you to invoke multiple functions in one script from the command line. Here is an example of using the same script to perform different operations:

foxe -run C:\script.foal:extract London
foxe -run C:\script.foal:merge London "New York"

If you specify a function name that is not found in the script, there will be an indication at the bottom of foxe_err.txt that also indicates the entry point it would have used if you had not specified one:

<entry_point arg_count="2" not_found="gormatxml">formatxml</entry_point>

If you do not specify the function and there is no main function in the script, the last function with a matching number of arguments is called. It chooses the last matching function because functions earlier in the script tend to be subroutines since in FOAL you can only call functions below where they are defined.

Posted 20 Nov 2010 updated 23 Apr 2011. Questions, comments? Contact info@firstobject.com.