lib/scripts/yxml.pl
author nipkow
Wed Aug 26 19:54:19 2009 +0200 (2009-08-26)
changeset 32416 4ea7648b6ae2
parent 29145 b1c6f4563df7
permissions -rw-r--r--
merged
     1 #
     2 # Author: Makarius
     3 #
     4 # yxml.pl - simple XML to YXML converter
     5 #
     6 
     7 use strict;
     8 use XML::Parser;
     9 
    10 binmode(STDOUT, ":utf8");
    11 
    12 sub handle_start {
    13   print chr(5), chr(6), $_[1];
    14   for (my $i = 2; $i <= $#_; $i++) {
    15     print ($i % 2 == 0 ? chr(6) : "=");
    16     print $_[$i];
    17   }
    18   print chr(5);
    19 }
    20 
    21 sub handle_end {
    22   print chr(5), chr(6), chr(5);
    23 }
    24 
    25 sub handle_char {
    26   print $_[1];
    27 }
    28 
    29 my $parser = new XML::Parser(Handlers =>
    30   {Start => \&handle_start,
    31     End => \&handle_end,
    32     Char => \&handle_char});
    33 
    34 $parser->parse(*STDIN) or die $!;
    35