lib/scripts/yxml.pl
author nipkow
Wed, 04 Mar 2009 10:47:20 +0100
changeset 30235 58d147683393
parent 29145 b1c6f4563df7
permissions -rw-r--r--
Made Option a separate theory and renamed option_map to Option.map
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26575
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
     1
#
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
     2
# Author: Makarius
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
     3
#
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
     4
# yxml.pl - simple XML to YXML converter
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
     5
#
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
     6
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
     7
use strict;
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
     8
use XML::Parser;
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
     9
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    10
binmode(STDOUT, ":utf8");
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    11
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    12
sub handle_start {
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    13
  print chr(5), chr(6), $_[1];
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    14
  for (my $i = 2; $i <= $#_; $i++) {
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    15
    print ($i % 2 == 0 ? chr(6) : "=");
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    16
    print $_[$i];
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    17
  }
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    18
  print chr(5);
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    19
}
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    20
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    21
sub handle_end {
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    22
  print chr(5), chr(6), chr(5);
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    23
}
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    24
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    25
sub handle_char {
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    26
  print $_[1];
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    27
}
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    28
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    29
my $parser = new XML::Parser(Handlers =>
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    30
  {Start => \&handle_start,
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    31
    End => \&handle_end,
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    32
    Char => \&handle_char});
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    33
26593
8375332b3c96 minimal error handling;
wenzelm
parents: 26575
diff changeset
    34
$parser->parse(*STDIN) or die $!;
26575
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    35