Boulder::XML(3pm)

πŸ“¦
version 1.30 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸŽ€ Boulder::XML πŸ’… (the 3pm manual, bestie edition)

okay so this whole page is about Boulder::XML β€” it's XML format input/output for Boulder streams. that's the vibe. no cap. let's get into it πŸ¦‹


✨ SYNOPSIS ✨

use Boulder::XML;

$stream = Boulder::XML->newFh;

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

look at that. iconic. it reads, it writes, it slays. 🫢


πŸ’« DESCRIPTION πŸ’«

Boulder::XML generates BoulderIO streams from XML files and/or streams. it's also able to output Boulder Stones in XML format. its semantics are similar to those of Boulder::Stream, except that there is never any pass-through behavior. not ever. not even once. periodt. πŸ’…

so here's the thing bestie β€” XML was not designed for streaming, so you gotta be a lil careful when you're reading an XML document into a series of Stones. take a look at this XML 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</Year>
  </Citation>
</Paper>

(yeah, the typos are canon. we don't fix canon. πŸ™ˆ)

ordinarily the document will be construed as a single Paper tag containing subtags Author, Date, Copyright, Abstract, and so on. but sometimes you wanna fetch out just the citation tags as a series of Stones, right? main character energy. in that 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. and 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. simple as that. ✨

it is possible to stream XML files, bestie. you can either:

  • separate them into separate documents and use the automatic ARGV processing features of the BoulderIO library, or
  • separate the XML documents using a delimiter string similar to the delimiters used in MIME multipart documents.

by default, BoulderIO uses a delimiter of <!--Boulder::XML-->. memorize that. iykyk. πŸŽ€

⚠️ okay BIG important thing: this is not a general XML parsing engine! instead, it is a way to represent BoulderIO tag/value streams in XML format. the module uses XML::Parser to parse the XML streams, and therefore any syntactic error in the stream can cause the XML parser to quit with an error. also, there are certain XML constructions that will not translate into BoulderIO format β€” specifically free text that contains embedded tags. this is OK:
<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. that's the rule, we don't make the rules, we just vibe with them. πŸ’œ


🧚 CONSTRUCTORS 🧚

$stream = Boulder::XML->new(*IN,*OUT);

$stream = Boulder::XML->new(-in=>*IN, -out=>*OUT, -tag=>$tag, -delim=>$delim, -strip=>$strip)

new() creates a new Boulder::XML stream that can be read from or written to. all arguments are optional. so chill. πŸ“

  • -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> (that's <Stone> when the POD renders it) 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.

$fh = Boulder::XML->newFh(*IN,*OUT);

$fh = Boulder::XML->newFh(-in=>*IN, -out=>*OUT, -tag=>$tag, -delim=>$delim, -strip=>$strip)

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 XML format. obsessed. 😭✨


🌈 METHODS 🌈

$stone = $stream->get()

$stream->put($stone)

$done = $stream->done

all these methods have the same semantics as the similar methods in Boulder::Stream, except that pass-through behavior doesn't apply. that's it. that's the section. πŸ’€


πŸ‘‘ AUTHOR πŸ‘‘

Lincoln D. Stein <lstein@cshl.org>, Cold Spring Harbor Laboratory, Cold Spring Harbor, NY. This module can be used and distributed on the same terms as Perl itself.

legend behavior, honestly. 🫑


πŸ¦‹ SEE ALSO πŸ¦‹

  • Boulder
  • Boulder::Stream
  • Stone

go read those next, bestie, they're all in the same friend group. πŸ’–


and that's the whole page! this one came from perl v5.34.0, dated 2022-06-08, and it was Boulder::XML(3pm) the whole time. bye bestie, go parse something cute πŸ’…πŸŒΈ

πŸ“¦ where this page comes from