Debian Codegraph @

reports/xml-dtd.ll

raw
1 /*
2 * @progname xml-dtd.ll
3 * @version 1.0
4 * @author Rafal T. Prinke
5 * @category
6 * @output XML DTD
7 * @description
8
9 This report produces an XML DTD (Document Type Definition)
10 from a LifeLines database. It is intended for comparing
11 tag usage and checking for structural inconsistencies
12 in a GEDCOM file - especially when sharing the same file
13 with others in a research project.
14
15 The LL report produces "tagpairs.txt" file which contains
16 a list of unique parent-child tags. Then the perl program
17 "dtd.pl" must be run, which will sort that list to
18 "tagpairs2.txt" and then write out "llines.dtd" file.
19
20 The perl program is appended at the end of this file.
21 It is rather clumsy but works. The resulting DTD does
22 not produce errors and can be further processed
23 with XML software - but could be better.
24
25 It may also be used in connection with my other
26 LL report - xmlize2.ll version 2.2 - which produces
27 an XML instance from a LifeLines database.
28
29 xml-dtd.ll - v. 0.2 Rafal T. Prinke, 8 May 2001
30 v. 1.0 Rafal T. Prinke, 30 June 2001
31
32 */
33
34
35 global(tagi)
36 global(content)
37
38 proc main ()
39 {
40
41 list(tagi)
42 table(content)
43
44
45 forindi(pers,x) {
46 call out(pers)
47 }
48 forfam(fm,x) {
49 call out(fm)
50 }
51 foreven(evn, n) {
52 call out(evn)
53 }
54 forsour(src, n) {
55 call out(src)
56 }
57 forothr(oth, n) {
58 call out(oth)
59 }
60
61 newfile("tagpairs.txt",0)
62 forlist(tagi,o,p) { getel(tagi,p) "\n" }
63
64 }
65
66
67 proc out(item)
68
69 {
70 traverse(root(item),y,level) {
71 set(para,concat(tag(parent(y)),"-",tag(y)))
72 set(pcdat,concat(tag(y),"-#PCDATA"))
73 set(xxref,concat(tag(y),"-|ID"))
74 set(xxpnt,concat(tag(y),"-|IDREF"))
75
76 /*** parent-child tag pair ***/
77
78 if(eqstr(substring(para,1,1),"-")) {
79 set(para,concat("LLGEDCOM-",tag(y)))
80 }
81 if(not(lookup(content,para))) {
82 push(tagi,para)
83 insert(content,para,1)
84 }
85
86 /*** references, xrefs and pcdata ***/
87
88
89 if(value(y)) {
90 if(reference(value(y))) {
91 if(not(lookup(content,xxpnt))) {
92 push(tagi,xxpnt)
93 insert(content,xxpnt,1) }
94 }
95 else {
96 if(not(lookup(content,pcdat))) {
97 push(tagi,pcdat)
98 insert(content,pcdat,1) }
99 }
100 }
101
102 if(xref(y)) {
103 if(not(lookup(content,xxref))) {
104 push(tagi,xxref)
105 insert(content,xxref,1)
106 }
107 }
108 }
109 }
110
111
112 /*** start of dtd.pl ***
113
114 #!C:\Perl\bin\perl.exe
115
116 $parent = "q";
117 $firstline = 1;
118 $attr = 0;
119
120 open FILE,"tagpairs.txt";
121 @tagi = <FILE>;
122 @stagi = sort @tagi;
123 close FILE;
124
125 open FILE,">tagpairs2.txt";
126 print FILE @stagi;
127 close FILE;
128
129 open FILE,"tagpairs2.txt";
130
131 open DTD,">llines.dtd";
132 close DTD;
133
134 open DTD,">>llines.dtd";
135
136 while ($line = <FILE>) {
137 chop $line;
138 @pair = split(/-/, $line);
139 if ($parent eq $pair[0]) {
140 if (substr($pair[1],0,1) ne "|") {
141 print DTD " | ", $pair[1];
142 $attr = 0;
143 }
144 else {
145 if ($attr == 0) { print DTD ")*>" }
146 print DTD "\n<!ATTLIST ", $pair[0], " ", substr($pair[1],1),
147 " ", substr($pair[1],1), " #REQUIRED >";
148 $attr = 1;
149 }
150 }
151
152 else { if ($firstline == 0) {
153 if (substr($pair[1],0,1) ne "|") {
154 if ($attr == 0) { print DTD ")*>" }
155 print DTD "\n", "<!ELEMENT ", $pair[0], " (", $pair[1];
156 $parent = $pair[0];
157 $attr = 0;
158 }
159 else {
160 if ($attr == 0) { print DTD ")*>" }
161 print DTD "\n<!ELEMENT ", $pair[0], " EMPTY>\n<!ATTLIST
162 ", $pair[0], " ", substr($pair[1],1), " ", substr($pair[1],1), "
163 #REQUIRED >";
164 $attr = 1;
165 $parent = $pair[0];
166 }
167 }
168 else {
169 if (substr($pair[1],0,1) ne "|") {
170 $firstline = 0;
171 print DTD "<!ELEMENT ", $pair[0], " (", $pair[1];
172 $parent = $pair[0];
173 $attr = 0;
174 }
175 else {
176 $firstline = 0;
177 if ($attr == 0) { print DTD ")*>" }
178 print DTD "\n<!ELEMENT ", $pair[0], " EMPTY>\n<!ATTLIST
179 ", $pair[0], " ", substr($pair[1],1), " ", substr($pair[1],1), "
180 #REQUIRED >";
181 $attr = 1;
182 $parent = $pair[0];
183 }
184 }
185 }
186 }
187
188 if ($attr == 0) { print DTD ")*>" }
189
190 close DTD;
191
192 *** end of dtd.pl ***/