This repository has been archived by the owner on Jun 9, 2018. It is now read-only.
/
xml.pir
91 lines (65 loc) · 1.54 KB
/
xml.pir
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Copyright (C) 2009, Parrot Foundation.
=head1 TITLE
xml.pir - A Xml demo.
=head2 Description
This program demonstrates the use of the modules :
=over
=item Xml::Sax::Xml
a XML SAX like parser
=item Handler::XmlWriter
a simple handler
=back
=cut
.namespace []
.sub 'onload' :anon :load :init
load_bytecode 'xml/sax/xml.pbc'
load_bytecode 'xml/handler/xmlwriter.pbc'
.end
.sub 'main' :main
.param pmc args
.local string filename
$P0 = shift args # progname
filename = shift args
.local pmc stream
stream = new 'StringHandle'
stream.'open'( 'xml', 'wr' )
.local pmc handler
handler = new ['Xml';'Handler';'XmlWriter']
handler.'stream'(stream)
.local pmc driver
driver = new [ 'Xml';'Sax';'Xml';'Compiler' ]
driver.'handler'(handler)
driver.'parse_file'(filename)
$S0 = stream.'readall'()
stream.'close'()
say $S0
.end
.sub 'xml_to_xml'
.param string data
.local pmc stream
stream = new 'StringHandle'
stream.'open'( 'xml', 'wr' )
.local pmc handler
handler = new ['Xml';'Handler';'XmlWriter']
handler.'stream'(stream)
.local pmc driver
driver = new [ 'Xml';'Sax';'Xml';'Compiler' ]
driver.'handler'(handler)
push_eh _handler
driver.'parse_string'(data)
pop_eh
$S0 = stream.'readall'()
$S0 .= "\n"
stream.'close'()
.return ($S0)
_handler:
.local pmc e
.get_results (e)
$S0 = e
.return ($S0)
.end
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: