1 | :- module(pltables_export_xml, [ | |
2 | xml_header/2, xml_footer/2, | |
3 | xml_table_header/2, xml_table_footer/2, | |
4 | xml_table_rows/2 | |
5 | ]). | |
6 | ||
7 | :- use_module(pltables_export_tools). | |
8 | :- use_module(pltables). | |
9 | ||
10 | :- use_module(probsrc(module_information)). | |
11 | ||
12 | :- module_info(group,pltables). | |
13 | :- module_info(description,'This module is used to export coverage tables to xml.'). | |
14 | ||
15 | % ---- | |
16 | % table headers | |
17 | % ---- | |
18 | xml_header(S, TableName) :- | |
19 | pltable(TableName, Attributes), | |
20 | write(S,'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n'), | |
21 | write(S,'<tables>'), | |
22 | ( member(headline(XHU), Attributes) -> | |
23 | xml_escape(XHU,XH), | |
24 | format(S, '<headline>~w</headline>\n', [XH]) | |
25 | ; true | |
26 | ). | |
27 | ||
28 | % ---- | |
29 | % table footers | |
30 | % ---- | |
31 | xml_footer(S, _TableName) :- | |
32 | write(S,'</tables>'). | |
33 | ||
34 | % ---- | |
35 | % table header / footer | |
36 | % ---- | |
37 | xml_table_header(S, TableName) :- | |
38 | write(S, '<table'), | |
39 | pltable(TableName, TableAttributes), | |
40 | pltable_header(TableName, Columns, _Attributes), | |
41 | ( | |
42 | member(description(XDU, _DescAttrs), TableAttributes) | |
43 | -> xml_escape(XDU,XD), | |
44 | format(S, ' description="~w"', [XD]) | |
45 | ; true | |
46 | ), | |
47 | write(S, '>\n'), | |
48 | write_xml_table_header(S, Columns). | |
49 | ||
50 | write_xml_table_header(S, Columns) :- | |
51 | write(S, ' <header>\n'), | |
52 | write_xml_table_header2(S, Columns), | |
53 | write(S, ' </header>\n'). | |
54 | ||
55 | write_xml_table_header2(_S, []). | |
56 | write_xml_table_header2(S, [Column | Columns]) :- | |
57 | xml_escape(Column, EscapedColumn), | |
58 | format(S, ' <column>~w</column>\n', [EscapedColumn]), | |
59 | write_xml_table_header2(S, Columns). | |
60 | ||
61 | xml_table_footer(S, _TableName) :- | |
62 | write(S,'</table>\n'). | |
63 | ||
64 | % ---- | |
65 | % table rows | |
66 | % ---- | |
67 | xml_table_rows(S, TableName) :- | |
68 | findall(Entries, pltables:pltable_row(TableName, Entries, _Attributes), ListOfEntries), | |
69 | write_xml_table_rows(S, ListOfEntries). | |
70 | ||
71 | write_xml_table_rows(_S, []). | |
72 | write_xml_table_rows(S, [Entries | MoreEntries]) :- | |
73 | write(S, ' <row>\n'), | |
74 | write_xml_table_row(S, Entries), | |
75 | write(S, ' </row>\n'), | |
76 | write_xml_table_rows(S, MoreEntries). | |
77 | ||
78 | write_xml_table_row(_S, []). | |
79 | write_xml_table_row(S, [Entry | Entries]) :- | |
80 | xml_escape(Entry, EscapedEntry), | |
81 | format(S, ' <cell>~w</cell>\n', [EscapedEntry]), | |
82 | write_xml_table_row(S, Entries). | |
83 | ||
84 | % ---- | |
85 | % escaping characters | |
86 | % ---- | |
87 | xml_escape(ToEscape, ToEscape). | |
88 | ||
89 | %xml_escape(ToEscape, Escaped) :- | |
90 | % atom(ToEscape), !, | |
91 | % atom_codes(ToEscape, CodeList), | |
92 | % xml_escape2(CodeList, EscapedCodeList), | |
93 | % atom_codes(Escaped, EscapedCodeList). | |
94 | %xml_escape(ToEscape, ToEscape). | |
95 | ||
96 | %xml_escape2([],[]). | |
97 | %xml_escape2([95|T], [92,95|EscT]) :- | |
98 | % xml_escape2(T, EscT). | |
99 | %xml_escape2([35|T], [92,35|EscT]) :- | |
100 | % xml_escape2(T, EscT). | |
101 | %xml_escape2([36|T], [92,36|EscT]) :- | |
102 | % xml_escape2(T, EscT). | |
103 | %xml_escape2([37|T], [92,37|EscT]) :- | |
104 | % xml_escape2(T, EscT). | |
105 | %xml_escape2([H|T], [H|EscT]) :- | |
106 | % H \= 95, | |
107 | % xml_escape2(T, EscT). |