-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaffodil.xqm
104 lines (86 loc) · 2.57 KB
/
daffodil.xqm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
(:~
A simple wrapper module for using the Daffodil CLI with BaseX.
@author: Kristian Kankainen
@copyright: MTÜ Keeleleek
:)
module namespace daffodil = "edu.illinois.ncsa.daffodil";
(:~
Compiles a DFDL schema and saves it in binary form.
@param: $daffodil the path to the daffodil binary
@param: $schema the path to the dfdl schema
@param: $outfile the path where to save the compiled parser
:)
declare function daffodil:save-parser($daffodil, $schema, $outfile as xs:string?)
{
let $outfile := if($outfile)
then($outfile)
else($schema || ".bin")
return
proc:system(
$daffodil,
(
"save-parser",
"--schema",
$schema,
$outfile
)
)
};
(:~
Generic function for using daffodil with a saved parser.
@param: $daffodil the path to the daffodil binary
@param: $parser the path to the saved parser
@param: $action parse or unparse
@param: $infile the path to the input file
@param: $outfile the path to the output tdml file
@param: $sys-encoding the system's encoding
:)
declare function daffodil:daffodil-cmd-use-saved-parser
($daffodil, $parser, $action, $infile, $outfile, $sys-encoding as xs:string?)
{
let $encoding := if($sys-encoding) then($sys-encoding) else("")
let $pfile :=
proc:system($daffodil,
(: argument list :)
( $action,
"--parser", $parser,
"--output", $outfile,
$infile
),
(: options :)
($encoding)
)
return
if($outfile = "-")
then(parse-xml($pfile))
else($pfile) (: @todo: but this is empty :)
};
(:~
Generic function for using daffodil with a DFDL schema.
@param: $daffodil the path to the daffodil binary
@param: $schema the path to the DFDL schema
@param: $action parse or unparse
@param: $infile the path to the input file
@param: $outfile the path to the output tdml file
@param: $sys-encoding the system's encoding
:)
declare function daffodil:daffodil-cmd-use-schema
($daffodil, $schema, $action, $infile, $outfile, $sys-encoding)
{
let $encoding := $sys-encoding
let $pfile :=
proc:system($daffodil,
(: argument list :)
( $action,
"--schema", $schema,
"--output", $outfile,
$infile
),
(: options :)
($encoding)
)
return
if($outfile = "-")
then(parse-xml($pfile))
else($pfile) (: @todo: but this is empty :)
};