File: soc2xml.pl

package info (click to toggle)
w3c-markup-validator 1.3%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,048 kB
  • sloc: javascript: 3,362; perl: 2,888; xml: 1,331; python: 427; sh: 216; makefile: 75
file content (38 lines) | stat: -rw-r--r-- 897 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl

use strict;
use warnings;

# Crude script for converting SGML Open Catalogs to XML catalogs.
# Usage: soc2xml.pl < catalog.soc > catalog.xml

sub esc
{
    (my $esc = shift) =~ s/&/&auml;/g;
    $esc =~ s/"/&quot;/g;
    $esc =~ s/'/&apos;/g;
    $esc =~ s/</&lt;/g;
    $esc =~ s/>/&gt;/g;
    $esc;
}

local $/ = undef;
my $soc = <>;

print <<'EOF';
<?xml version="1.0"?>
<!-- Automatically generated from SGML Open Catalog - don't edit, regenerate -->
<!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN" "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
EOF

while ($soc =~ /(PUBLIC|SYSTEM)\s+"([^"]+)"\s+"([^"]+)"/g) {
    my $pubsys = lc($1);
    printf <<'EOF', $pubsys, $pubsys, esc($2), esc($3);
  <%s %sId="%s" uri="%s" />
EOF
}

print <<'EOF';
</catalog>
EOF