YML – Why a Markup Language?!
There are to possibilities to handle YML files: the YML compiler and the YML/YSLT processor.
The YML compiler is a small Python script. It provides the command line front end yml2c
. As default, it compiles your script and outputs to stdout, that usually is the terminal. Your shell provides options to redirect the output into a pipe or a file.
So to use it, just enter yml2c
followed by the filename of your YML script:
% yml2c myscript.yml2 > myscript.result
The yml2c
command has the following options:
Show a help message and exit.
Use the syntax of YML 2 version 1.x (compatibility mode).
Emit line numbers into the resulting XML for debugging purposes.
encoding of input files (default: UTF-8)
Precede YML_PATH
by a colon separated INCLUDE_PATH
(semicolon separated on Windows) to search for include files.
Does nothing (only there for compatibility with older versions of yml2c
).
Unicode normalization (none, NFD, NFKD, NFC, NFKC, FCD, default is NFC)
Don't output to stdout, instead place output in file FILE
.
Parse only, then output pyAST as text to stdout. The pyAST is the Abstract Syntax Tree of the parsed script as Python data structure.
Show version and Copyleft information of the YML implementation.
If YML_PATH
is set to a colon separated path list (semicolon separated on Windows), then the include
statement searches these paths. If YML_PATH
is not set, the local directory .
is searched for files. The system location for .yml2
and .ysl2
files is always searched afterwards.
If you're processing more complex tasks, say, executing an YSLT script over some YML files, the YML/YSLT processor will possible fit better to your needs.
To use it, enter yml2proc -y
followed by the filename of your YSLT script, followed by the filenames of your YML input files:
% yml2proc -y myscript.ysl2 inputfile.yml2 > myscript.result
The YML/YSLT processor requires the lxml Python library.
The YML/YSLT processor has the following options:
Show a help message and exit.
Use the syntax of YML 2 version 1.x (compatibility mode).
Emit line numbers into the resulting XML for debugging purposes.
switch on debug tracing to stderr; this enables the functionality of the debug(msg) and assert yml:assert(test, msg) YSLT functions.
encoding of input files (default: UTF-8)
Precede YML_PATH
by a colon separated INCLUDE_PATH
(semicolon separated on Windows) to search for include files.
Does nothing (only there for compatibility with older versions of yml2proc
).
Use an empty input document for YSLT or XSLT processing
Unicode normalization (none, NFD, NFKD, NFC, NFKC, FCD, default is NFC)
Don't output to stdout, instead place output in file FILE
.
Parse only, then output pyAST as text to stdout. The pyAST is the Abstract Syntax Tree of the parsed script as Python data structure.
Execute XPath expression XPATH and print result
If you omit -y YSLTSCRIPT, then the result is printed. If you have an additional -y YSLTSCRIPT parameter, then your YSLT script is processing the result of the XPath expression only instead of processing the complete content of your input documents
Pretty print output adding whitespace
Input documents are XML already, don't try to convert them from YML
Execute YSLT script YSLTSCRIPT
Execute XSLT script XSLTSCRIPT
Call XSLT or YSLT script with dictionary PARAMS as XPath parameters. PARAMS is a Python expression which evaluates to a Python dictionary.
Sample:
yml2proc -y myscript -d 'dict(a=3, b="element[@name=2]")'
Call XSLT or YSLT script with dictionary STRINGPARAMS as string parameters. STRINGPARAMS is a Python expression which evaluates to a Python dictionary.
Sample:
yml2proc -y myscript -s 'dict(forename="Hans", name="Meier")'
Convert XML to normalized YML. Equivalent to -xy xml2yml.ysl2
Show version and Copyleft information of the YML implementation and exit.
If YML_PATH
is set to a colon separated path list (semicolon separated on Windows), then the include
statement searches these paths. If YML_PATH
is not set, the local directory .
is searched for files. The system location for .yml2
and .ysl2
files is always searched afterwards.
If you want to use YSLT with yml2c
instead of yml2proc
, you additionally need an XSLT processor.
For that case, I recommend the xsltproc tool.
To process YSLT, just use a pipe with the xsltproc
command:
% yml2c customer.ysl2 | xsltproc - customer.xml > customer.html
Sometimes, you may want to have more human readable output with yml2c
. So an XML renicing tool can be helpful.
The XMLStarlet command line tool may be of interest.
Have a look on its fo
command.
See also the tips for a Windows tool chain for YML.
You can here download the newest release of YML.