1Boulder::XML(3) User Contributed Perl Documentation Boulder::XML(3)
2
3
4
6 Boulder::XML - XML format input/output for Boulder streams
7
9 use Boulder::XML;
10
11 $stream = Boulder::XML->newFh;
12
13 while ($stone = <$stream>) {
14 print $stream $stone;
15 }
16
18 Boulder::XML generates BoulderIO streams from XML files and/or streams.
19 It is also able to output Boulder Stones in XML format. Its semantics
20 are similar to those of Boulder::Stream, except that there is never any
21 pass-through behavior.
22
23 Because XML was not designed for streaming, some care must be taken
24 when reading an XML document into a series of Stones. Consider this
25 XML document:
26
27 <?xml version="1.0" standalone="yes"?>
28
29 <Paper>
30 <Author>Lincoln Stein</Author>
31 <Author>Jean Siao</Author>
32 <Date>September 29, 1999</Date>
33 <Copyright copyrighted="yes">1999 Lincoln Stein</Copright>
34 <Abstract>
35 This is the abstract. It is not anything very fancy,
36 but it will do.
37 </Abstract>
38 <Citation>
39 <Author>Fitchberg J</Author>
40 <Journal>Journal of Irreproducible Results</Journal>
41 <Volume>23</Volume>
42 <Year>1998</Volume>
43 </Citation>
44 <Citation>
45 <Author>Clemenson V</Author>
46 <Journal>Ecumenica</Journal>
47 <Volume>10</Volume>
48 <Year>1968</Volume>
49 </Citation>
50 <Citation>
51 <Author>Ruggles M</Author>
52 <Journal>Journal of Aesthetic Surgery</Journal>
53 <Volume>10</Volume>
54 <Year>1999</Volume>
55 </Citation>
56 </Paper>
57
58 Ordinarily the document will be construed as a single Paper tag
59 containing subtags Author, Date, Copyright, Abstract, and so on.
60 However it might be desirable to fetch out just the citation tags as a
61 series of Stones. In this case, you can declare Citation to be the top
62 level tag by passing the -tag argument to new(). Now calling get() will
63 return each of the three Citation sections in turn. If no tag is
64 explicitly declared to be the top level tag, then Boulder::XML will
65 take the first tag it sees in the document.
66
67 It is possible to stream XML files. You can either separate them into
68 separate documents and use the automatic ARGV processing features of
69 the BoulderIO library, or separate the XML documents using a delimiter
70 string similar to the delimiters used in MIME multipart documents. By
71 default, BoulderIO uses a delimiter of <!--Boulder::XML-->.
72
73 This is not a general XML parsing engine! Instead, it is a way to
74 represent BoulderIO tag/value streams in XML format. The module uses
75 XML::Parser to parse the XML streams, and therefore any syntactic error
76 in the stream can cause the XML parser to quit with an error. Another
77 thing to be aware of is that there are certain XML constructions that
78 will not translate into BoulderIO format, specifically free text that
79 contains embedded tags. This is OK:
80
81 <Author>Jean Siao</Author>
82
83 but this is not:
84
85 <Author>The <Emphatic>extremely illustrious</Emphatic> Jean Siao</Author>
86
87 In BoulderIO format, tags can contain other tags or text, but cannot
88 contain a mixture of tags and text.
89
90 CONSTRUCTORS
91 $stream = Boulder::XML->new(*IN,*OUT);
92 $stream =
93 Boulder::XML->new(-in=>*IN,-out=>*OUT,-tag=>$tag,-delim=>$delim,-strip=>$strip)
94 new() creates a new Boulder::XML stream that can be read from or
95 written to. All arguments are optional.
96
97 -in Filehandle to read from.
98 If a file name is provided, will open the file.
99 Defaults to the magic <> filehandle.
100
101 -out Filehandle to write to.
102 If a file name is provided, will open the file for writing.
103 Defaults to STDOUT
104
105 -tag The top-level XML tag to consider as the Stone record. Defaults
106 to the first tag seen when reading from an XML file, or to
107 E<lt>StoneE<gt> when writing to an output stream without
108 previously having read.
109
110 -delim Delimiter to use for delimiting multiple Stone objects in an
111 XML stream.
112
113 -strip If true, automatically strips leading and trailing whitespace
114 from text contained within tags.
115
116 $fh = Boulder::XML->newFh(*IN,*OUT);
117 $fh =
118 Boulder::XML->newFh(-in=>*IN,-out=>*OUT,-tag=>$tag,-delim=>$delim,-strip=>$strip)
119 The newFh() constructor creates a tied filehandle that can read and
120 write Boulder::XML streams. Invoking <> on the filehandle will
121 perform a get(), returning a Stone object. Calling print() on the
122 filehandle will perform a put(), writing a Stone object to output
123 in XML format.
124
125 METHODS
126 $stone = $stream->get()
127 $stream->put($stone)
128 $done = $stream->done
129 All these methods have the same semantics as the similar methods in
130 Boulder::Stream, except that pass-through behavior doesn't apply.
131
133 Lincoln D. Stein <lstein@cshl.org>, Cold Spring Harbor Laboratory, Cold
134 Spring Harbor, NY. This module can be used and distributed on the same
135 terms as Perl itself.
136
138 Boulder, Boulder::Stream, Stone
139
140
141
142perl v5.30.0 2019-07-26 Boulder::XML(3)