27 |
submodule ($_, $Info); |
submodule ($_, $Info); |
28 |
} elsif ($_->local_name eq 'Model') { |
} elsif ($_->local_name eq 'Model') { |
29 |
model_module ($_, $Info); |
model_module ($_, $Info); |
30 |
|
$Info->{has_model} = 1; |
31 |
} elsif ($_->local_name eq 'Driver') { |
} elsif ($_->local_name eq 'Driver') { |
32 |
dtd_driver ($_, $Info); |
dtd_driver ($_, $Info); |
33 |
} |
} |
52 |
$type =~ s/\s+//g; |
$type =~ s/\s+//g; |
53 |
$type; |
$type; |
54 |
} |
} |
55 |
|
sub system_id_of ($$;%) { |
56 |
|
my ($src, $Info, %opt) = @_; |
57 |
|
my $sysid = $src->get_attribute_value ('SYSTEM'); |
58 |
|
if ($sysid =~ /<([^>]+)>/) { |
59 |
|
return $1; |
60 |
|
} else { |
61 |
|
return $opt{base}.($sysid || $opt{default}); |
62 |
|
} |
63 |
|
} |
64 |
sub external_id_of ($$;%) { |
sub external_id_of ($$;%) { |
65 |
my ($src, $Info, %opt) = @_; |
my ($src, $Info, %opt) = @_; |
66 |
my $sysid = $opt{base}.($src->get_attribute_value ('SYSTEM') || $opt{default}); |
my $sysid = system_id_of ($src, $Info, %opt); |
67 |
my $pubid = $src->get_attribute_value ('PUBLIC'); |
my $pubid = $src->get_attribute_value ('PUBLIC'); |
68 |
if ($pubid) { |
if ($pubid) { |
69 |
if ($sysid) { |
if ($sysid) { |
125 |
$model =~ s/(?<![%#.])((?:\$|\b)$nonsymbol+(?::$nonsymbol+)?|\$?:$nonsymbol+|"[^"]+")/get_model_token ($1, $Info)/ge; |
$model =~ s/(?<![%#.])((?:\$|\b)$nonsymbol+(?::$nonsymbol+)?|\$?:$nonsymbol+|"[^"]+")/get_model_token ($1, $Info)/ge; |
126 |
$model; |
$model; |
127 |
} |
} |
128 |
|
sub sparalit ($) { |
129 |
|
my $s = paralit (shift); |
130 |
|
$s =~ s/&/&/g; |
131 |
|
$s =~ s/%/%/g; |
132 |
|
$s; |
133 |
|
} |
134 |
sub paralit ($) { |
sub paralit ($) { |
135 |
my $s = shift; |
my $s = shift; |
136 |
if ($s =~ /"/) { |
if ($s =~ /"/) { |
162 |
$desc; |
$desc; |
163 |
} |
} |
164 |
|
|
165 |
|
sub entity_declaration ($$;%) { |
166 |
|
my ($src, $Info, %opt) = @_; |
167 |
|
my $val; |
168 |
|
if ($src->get_attribute_value ('ID') |
169 |
|
|| $src->get_attribute_value ('SYSTEM') |
170 |
|
|| $src->get_attribute_value ('PUBLIC')) { |
171 |
|
$val = "\n\t".external_id_of ($src, $Info, default => $src->get_attribute_value ('ID')); |
172 |
|
} elsif (ref $src->get_attribute ('Declaration')) { |
173 |
|
$val = "\n\t".sparalit submodule_declarations ($src->get_attribute ('Declaration'), $Info); |
174 |
|
} else { |
175 |
|
$val = paralit $src->get_attribute_value ('EntityValue'); |
176 |
|
} |
177 |
|
my $s = <<EOH; |
178 |
|
@{[description ($src, $Info)]}<!ENTITY @{[$opt{param}?'% ':'']}@{[$src->get_attribute_value ('Name')]} $val> |
179 |
|
|
180 |
|
EOH |
181 |
|
$s; |
182 |
|
} |
183 |
|
|
184 |
sub dtd_driver ($$) { |
sub dtd_driver ($$) { |
185 |
my ($src, $Info) = @_; |
my ($src, $Info) = @_; |
189 |
for my $src (@{$src->child_nodes}) { |
for my $src (@{$src->child_nodes}) { |
190 |
if ($src->local_name eq 'Module') { |
if ($src->local_name eq 'Module') { |
191 |
$s .= dtd_driver_load_module ($src, $Info); |
$s .= dtd_driver_load_module ($src, $Info); |
192 |
|
} elsif ($src->local_name eq 'DTD') { |
193 |
|
$s .= dtd_driver_load_dtd ($src, $Info); |
194 |
} elsif ($src->local_name eq 'ModuleSet') { |
} elsif ($src->local_name eq 'ModuleSet') { |
195 |
push @module_set, $src; |
push @module_set, $src; |
196 |
} elsif ($src->local_name =~ /^(?:QName|Attribute|Datatype|Notation)Module/) { |
} elsif ($src->local_name =~ /^(?:QName|Attribute|Datatype|Notation)Module/) { |
200 |
$s .= submodule_declarations ($src, $Info); |
$s .= submodule_declarations ($src, $Info); |
201 |
$s .= qq(]]>\n); |
$s .= qq(]]>\n); |
202 |
} elsif ($src->local_name eq 'GeneralEntity') { |
} elsif ($src->local_name eq 'GeneralEntity') { |
203 |
$s .= qq(@{[description ($src, $Info)]}<!ENTITY @{[$src->get_attribute_value ('Name')]} @{[paralit $src->get_attribute_value ('EntityValue')]}>\n\n); |
$s .= entity_declaration ($src, $Info, param => 0); |
204 |
} elsif ($src->local_name eq 'ParameterEntity') { |
} elsif ($src->local_name eq 'ParameterEntity') { |
205 |
$s .= qq(@{[description ($src, $Info)]}<!ENTITY % @{[$src->get_attribute_value ('Name')]} @{[paralit $src->get_attribute_value ('EntityValue')]}>\n\n); |
$s .= entity_declaration ($src, $Info, param => 1); |
206 |
} |
} |
207 |
} |
} |
208 |
|
|
209 |
$s{ModelModule} = <<EOH; |
$s{ModelModule} = $src->get_attribute_value ('NoModelModule') ? '' : |
210 |
|
$Info->{has_model} ? <<EOH : ''; |
211 |
<!-- Document Model module --> |
<!-- Document Model module --> |
212 |
<!ENTITY % $Info->{ID}-model.module "INCLUDE"> |
<!ENTITY % $Info->{ID}-model.module "INCLUDE"> |
213 |
<![%$Info->{ID}-model.module;[ |
<![%$Info->{ID}-model.module;[ |
285 |
|
|
286 |
my $s .= <<EOH; |
my $s .= <<EOH; |
287 |
@{[description ($src, $Info, context => 'load_module', id => $src->local_name)]}<![%$module_set_name.module;[ |
@{[description ($src, $Info, context => 'load_module', id => $src->local_name)]}<![%$module_set_name.module;[ |
288 |
<!ENTITY % $module_name.module "INCLUDE"> |
<!ENTITY % $module_name.module "@{[$src->get_attribute_value ('Default') >= 0 ? 'INCLUDE' : 'IGNORE']}"> |
289 |
<![%$module_name.module;[ |
<![%$module_name.module;[ |
290 |
@{[submodule_declarations ($src, $Info)]}<!ENTITY % $module_name.decl |
@{[submodule_declarations ($src, $Info)]}<!ENTITY % $module_name.decl |
291 |
@{[paralit external_id_of ($src, $Info, default => qq($module_hyphen_name.mod), base => qq(%$module_set_name.sysid.base;))]}> |
@{[paralit external_id_of ($src, $Info, default => qq($module_hyphen_name.mod), base => qq(%$module_set_name.sysid.base;))]}> |
296 |
EOH |
EOH |
297 |
$s; |
$s; |
298 |
} |
} |
299 |
|
|
300 |
|
sub dtd_driver_load_dtd ($$) { |
301 |
|
my ($src, $Info) = @_; |
302 |
|
my $module_set_name = $src->get_attribute_value ('ID'); |
303 |
|
|
304 |
|
my $s .= <<EOH; |
305 |
|
@{[description ($src, $Info)]}<![%$module_set_name.module;[ |
306 |
|
@{[submodule_declarations ($src, $Info)]}<!ENTITY % $module_set_name.dtd.sysid "@{[system_id_of ($src, $Info, default => $src->get_attribute_value ('ID').'.dtd', base => qq(%$module_set_name.sysid.base;))]}"> |
307 |
|
@{[do{ |
308 |
|
my $pubid = $src->get_attribute_value ('PUBLIC'); |
309 |
|
if ($pubid) { |
310 |
|
qq(<!ENTITY % $module_set_name.dtd.fpi "$pubid">\n<!ENTITY % $module_set_name.dtd.fpi.defined "INCLUDE">\n); |
311 |
|
} else { |
312 |
|
qq(<!ENTITY % $module_set_name.dtd.fpi "">\n<!ENTITY % $module_set_name.dtd.fpi.defined "IGNORE">\n); |
313 |
|
} |
314 |
|
}]} |
315 |
|
<![%$module_set_name.dtd.fpi.defined;[ |
316 |
|
<!ENTITY % $module_set_name.dtd.decl |
317 |
|
'PUBLIC "%$module_set_name.dtd.fpi;" |
318 |
|
"%$module_set_name.dtd.sysid;"'> |
319 |
|
]]> |
320 |
|
<!ENTITY % $module_set_name.dtd.decl |
321 |
|
'SYSTEM "%$module_set_name.dtd.sysid;"'> |
322 |
|
<!ENTITY % $module_set_name.dtd %$module_set_name.dtd.decl;> |
323 |
|
%$module_set_name.dtd;]]> |
324 |
|
|
325 |
|
EOH |
326 |
|
$s; |
327 |
|
} |
328 |
|
|
329 |
sub model_module ($$) { |
sub model_module ($$) { |
330 |
my ($src, $Info) = @_; |
my ($src, $Info) = @_; |
331 |
my $s = ''; |
my $s = ''; |
332 |
for my $src (@{$src->child_nodes}) { |
for my $src (@{$src->child_nodes}) { |
333 |
if ($src->local_name eq 'Class') { |
if ($src->local_name eq 'Class') { |
334 |
$s .= qq(@{[get_desc ($src, $Info)]}<!ENTITY % @{[class_name_of ($src, $Info)]} @{[paralit convert_content_model ($src, $Info)]}>\n\n); |
$s .= qq(@{[description ($src, $Info)]}<!ENTITY % @{[class_name_of ($src, $Info)]} @{[paralit convert_content_model ($src, $Info)]}>\n\n); |
335 |
} elsif ($src->local_name eq 'Content') { |
} elsif ($src->local_name eq 'Content') { |
336 |
$s .= element_content_def ($src, $Info); |
$s .= element_content_def ($src, $Info); |
337 |
} |
} |
368 |
my $s = <<EOH; |
my $s = <<EOH; |
369 |
<!ENTITY % NS.prefixed "@{[$ns->get_attribute_value ('UsePrefix')==1? |
<!ENTITY % NS.prefixed "@{[$ns->get_attribute_value ('UsePrefix')==1? |
370 |
q(INCLUDE):q(IGNORE)]}"> |
q(INCLUDE):q(IGNORE)]}"> |
371 |
|
|
372 |
|
<!-- 1. Declare conditional section keyword, used to activate namespace prefixing. --> |
373 |
<!ENTITY % $ID.prefixed "@{[$ns->get_attribute_value ('UsePrefix')==1? |
<!ENTITY % $ID.prefixed "@{[$ns->get_attribute_value ('UsePrefix')==1? |
374 |
q(INCLUDE): |
q(INCLUDE): |
375 |
$ns->get_attribute_value ('UsePrefix')==-1? |
$ns->get_attribute_value ('UsePrefix')==-1? |
376 |
q(IGNORE): |
q(IGNORE): |
377 |
q(%NS.prefixed;)]}"> |
q(%NS.prefixed;)]}"> |
378 |
|
|
379 |
|
<!-- 2. Declare a parameter entity containing the namespace name. --> |
380 |
<!ENTITY % $ID.xmlns "@{[$ns->get_attribute_value ('Name')]}"> |
<!ENTITY % $ID.xmlns "@{[$ns->get_attribute_value ('Name')]}"> |
381 |
|
|
382 |
|
<!-- 3. Declare parameter entities containing the default namespace prefix |
383 |
|
string to use when prefixing is enabled. --> |
384 |
<!ENTITY % $ID.prefix "@{[$ns->get_attribute_value ('DefaultPrefix')]}"> |
<!ENTITY % $ID.prefix "@{[$ns->get_attribute_value ('DefaultPrefix')]}"> |
385 |
|
|
386 |
|
<!-- 4. Declare parameter entities containing the colonized prefix |
387 |
|
used when prefixing is active, an empty string when it is not. --> |
388 |
<![%$ID.prefixed;[ |
<![%$ID.prefixed;[ |
389 |
<!ENTITY % $ID.pfx "%$ID.prefix;:"> |
<!ENTITY % $ID.pfx "%$ID.prefix;:"> |
390 |
]]> |
]]> |
391 |
<!ENTITY % $ID.pfx ""> |
<!ENTITY % $ID.pfx ""> |
392 |
|
|
393 |
|
<!-- declare qualified name extensions here --> |
394 |
|
<!ENTITY % ${ID}-qname-extra.mod ""> |
395 |
|
%${ID}-qname-extra.mod; |
396 |
|
|
397 |
|
<!-- 5. May be redeclared to contain any foreign namespace declaration |
398 |
|
attributes for namespaces embedded in XML. --> |
399 |
<!ENTITY % $ID.xmlns.extra.attrib ""> |
<!ENTITY % $ID.xmlns.extra.attrib ""> |
400 |
|
|
401 |
<![%$ID.prefixed;[ |
<![%$ID.prefixed;[ |
413 |
<!ENTITY % NS.decl.attrib |
<!ENTITY % NS.decl.attrib |
414 |
"%$ID.xmlns.extra.attrib;"> |
"%$ID.xmlns.extra.attrib;"> |
415 |
|
|
416 |
|
<!-- Declare a parameter entity containing all XML namespace declaration |
417 |
|
attributes used, including a default xmlns declaration when prefixing |
418 |
|
is inactive. --> |
419 |
<![%$ID.prefixed;[ |
<![%$ID.prefixed;[ |
420 |
<!ENTITY % $ID.xmlns.attrib |
<!ENTITY % $ID.xmlns.attrib |
421 |
"%NS.decl.attrib;"> |
"%NS.decl.attrib;"> |
424 |
"%$ID.xmlns.decl.attrib; |
"%$ID.xmlns.decl.attrib; |
425 |
%NS.decl.attrib;"> |
%NS.decl.attrib;"> |
426 |
|
|
427 |
|
<!-- 6. Declare parameter entities used to provide namespace-qualified |
428 |
|
names for all element types and global attribute names. --> |
429 |
EOH |
EOH |
430 |
for my $lname (keys %{$Info->{QName}}) { |
for my $lname (keys %{$Info->{QName}}) { |
431 |
$s .= qq(<!ENTITY % $Info->{ID}.$lname.qname "%$Info->{ID}.pfx;$lname">\n); |
$s .= qq(<!ENTITY % $Info->{ID}.$lname.qname "%$Info->{ID}.pfx;$lname">\n); |
600 |
$s .= attlist_def ($src, $Info); |
$s .= attlist_def ($src, $Info); |
601 |
} elsif ($src->local_name eq 'AttributeSet') { |
} elsif ($src->local_name eq 'AttributeSet') { |
602 |
$s .= attset_def ($src, $Info); |
$s .= attset_def ($src, $Info); |
603 |
|
} elsif ($src->local_name eq 'Class') { |
604 |
|
$s .= qq(@{[description ($src, $Info)]}<!ENTITY % @{[class_name_of ($src, $Info)]} @{[paralit convert_content_model ($src, $Info)]}>\n\n); |
605 |
} elsif ($src->local_name eq 'Content') { |
} elsif ($src->local_name eq 'Content') { |
606 |
$s .= element_content_def ($src, $Info); |
$s .= element_content_def ($src, $Info); |
607 |
} elsif ($src->local_name eq 'IfModuleSet') { |
} elsif ($src->local_name eq 'IfModuleSet') { |
612 |
$s .= qq(<!ENTITY % @{[name_of ($src, $Info)]}.element "@{[$src->get_attribute_value ('Use')>0?'INCLUDE':'IGNORE']}">\n); |
$s .= qq(<!ENTITY % @{[name_of ($src, $Info)]}.element "@{[$src->get_attribute_value ('Use')>0?'INCLUDE':'IGNORE']}">\n); |
613 |
} elsif ($src->local_name eq 'AttributeSwitch') { |
} elsif ($src->local_name eq 'AttributeSwitch') { |
614 |
$s .= qq(<!ENTITY % @{[name_of ($src, $Info)]}.attlist "@{[$src->get_attribute_value ('Use')>0?'INCLUDE':'IGNORE']}">\n); |
$s .= qq(<!ENTITY % @{[name_of ($src, $Info)]}.attlist "@{[$src->get_attribute_value ('Use')>0?'INCLUDE':'IGNORE']}">\n); |
615 |
|
} elsif ($src->local_name eq 'ModuleSwitch') { |
616 |
|
$s .= qq(<!ENTITY % @{[name_of ($src, $Info)]}.module "@{[$src->get_attribute_value ('Use')>0?'INCLUDE':'IGNORE']}">\n); |
617 |
|
} elsif ($src->local_name eq 'GeneralEntity') { |
618 |
|
$s .= entity_declaration ($src, $Info, param => 0); |
619 |
} elsif ($src->local_name eq 'ParameterEntity') { |
} elsif ($src->local_name eq 'ParameterEntity') { |
620 |
$s .= qq(@{[description ($src, $Info)]}<!ENTITY % @{[$src->get_attribute_value ('Name')]} @{[paralit $src->get_attribute_value ('EntityValue')]}>\n); |
$s .= entity_declaration ($src, $Info, param => 1); |
621 |
} |
} |
622 |
} |
} |
623 |
$s; |
$s; |
703 |
struct => q/Structual/, |
struct => q/Structual/, |
704 |
}->{$id} |
}->{$id} |
705 |
|| $id; |
|| $id; |
706 |
|
return unless $s; |
707 |
|
|
708 |
my $r = <<EOH; |
my $r = <<EOH; |
709 |
<!-- $Info->{Name} : $name Module |
<!-- $Info->{Name} : $name Module |