SYNOPSIS

   use Boulder::XML;

   $stream = Boulder::XML->newFh;

   while ($stone = <$stream>) {
        print $stream $stone;
   }

DESCRIPTION

Boulder::XML generates BoulderIO streams from \s-1XML\s0 files and/or streams. It is also able to output Boulder Stones in \s-1XML\s0 format. Its semantics are similar to those of Boulder::Stream, except that there is never any pass-through behavior.

Because \s-1XML\s0 was not designed for streaming, some care must be taken when reading an \s-1XML\s0 document into a series of Stones. Consider this \s-1XML\s0 document:

<?xml version="1.0" standalone="yes"?>

<Paper> <Author>Lincoln Stein</Author> <Author>Jean Siao</Author> <Date>September 29, 1999</Date> <Copyright copyrighted="yes">1999 Lincoln Stein</Copright> <Abstract> This is the abstract. It is not anything very fancy, but it will do. </Abstract> <Citation> <Author>Fitchberg J</Author> <Journal>Journal of Irreproducible Results</Journal> <Volume>23</Volume> <Year>1998</Volume> </Citation> <Citation> <Author>Clemenson V</Author> <Journal>Ecumenica</Journal> <Volume>10</Volume> <Year>1968</Volume> </Citation> <Citation> <Author>Ruggles M</Author> <Journal>Journal of Aesthetic Surgery</Journal> <Volume>10</Volume> <Year>1999</Volume> </Citation> </Paper>

Ordinarily the document will be construed as a single Paper tag containing subtags Author, Date, Copyright, Abstract, and so on. However it might be desirable to fetch out just the citation tags as a series of Stones. In this case, you can declare Citation to be the top level tag by passing the -tag argument to new(). Now calling get() will return each of the three Citation sections in turn. If no tag is explicitly declared to be the top level tag, then Boulder::XML will take the first tag it sees in the document.

It is possible to stream \s-1XML\s0 files. You can either separate them into separate documents and use the automatic \s-1ARGV\s0 processing features of the BoulderIO library, or separate the \s-1XML\s0 documents using a delimiter string similar to the delimiters used in \s-1MIME\s0 multipart documents. By default, BoulderIO uses a delimiter of <!--Boulder::XML-->.

This is not a general \s-1XML\s0 parsing engine! Instead, it is a way to represent BoulderIO tag/value streams in \s-1XML\s0 format. The module uses XML::Parser to parse the \s-1XML\s0 streams, and therefore any syntactic error in the stream can cause the \s-1XML\s0 parser to quit with an error. Another thing to be aware of is that there are certain \s-1XML\s0 constructions that will not translate into BoulderIO format, specifically free text that contains embedded tags. This is \s-1OK:\s0

<Author>Jean Siao</Author>

but this is not:

<Author>The <Emphatic>extremely illustrious</Emphatic> Jean Siao</Author>

In BoulderIO format, tags can contain other tags or text, but cannot contain a mixture of tags and text.

\s-1CONSTRUCTORS\s0

new() creates a new Boulder::XML stream that can be read from or written to. All arguments are optional. -in Filehandle to read from. If a file name is provided, will open the file. Defaults to the magic <> filehandle.

-out Filehandle to write to. If a file name is provided, will open the file for writing. Defaults to STDOUT

-tag The top-level XML tag to consider as the Stone record. Defaults to the first tag seen when reading from an XML file, or to E<lt>StoneE<gt> when writing to an output stream without previously having read.

-delim Delimiter to use for delimiting multiple Stone objects in an XML stream.

-strip If true, automatically strips leading and trailing whitespace from text contained within tags. The newFh() constructor creates a tied filehandle that can read and write Boulder::XML streams. Invoking <> on the filehandle will perform a get(), returning a Stone object. Calling print() on the filehandle will perform a put(), writing a Stone object to output in \s-1XML\s0 format.

\s-1METHODS\s0

All these methods have the same semantics as the similar methods in Boulder::Stream, except that pass-through behavior doesn't apply.

AUTHOR

Lincoln D. Stein <[email protected]>, Cold Spring Harbor Laboratory, Cold Spring Harbor, \s-1NY\s0. This module can be used and distributed on the same terms as Perl itself.

RELATED TO Boulder::XML…

Boulder, Boulder::Stream, Stone