lib/scripts/yxml.pl
author wenzelm
Tue, 08 Apr 2008 15:47:05 +0200
changeset 26575 042617a1c86c
child 26593 8375332b3c96
permissions -rw-r--r--
support for YXML notation -- XML done right;
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
# $Id$
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
     3
# Author: Makarius
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
     4
#
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
     5
# yxml.pl - simple XML to YXML converter
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
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
     8
use strict;
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
     9
use XML::Parser;
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    10
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    11
binmode(STDOUT, ":utf8");
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    12
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    13
sub handle_start {
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    14
  print chr(5), chr(6), $_[1];
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    15
  for (my $i = 2; $i <= $#_; $i++) {
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    16
    print ($i % 2 == 0 ? chr(6) : "=");
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    17
    print $_[$i];
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    18
  }
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    19
  print chr(5);
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
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    22
sub handle_end {
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    23
  print chr(5), chr(6), chr(5);
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
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    26
sub handle_char {
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    27
  print $_[1];
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
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    30
my $parser = new XML::Parser(Handlers =>
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    31
  {Start => \&handle_start,
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    32
    End => \&handle_end,
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    33
    Char => \&handle_char});
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    34
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    35
$parser->parse(*STDIN);
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    36