module XML::Reader

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Just a small message to say that my module XML::Reader is on CPAN:

It is most useful to extract XML sequentially (uses constant memory,
even with huge XML files).

Feedback is most welcome.

Here is an example from the documentation:

  use XML::Reader;

  my $rdr = XML::Reader->new($line2, {filter => 5},
    { root => 'customer',       branch => ['/@name', '/street', '/
city'] },
    { root => 'p',              branch => '*' },

  my $out0 = '';
  my $out1 = '';

  while ($rdr->iterate) {
      if ($rdr->rx == 0) {
          my @rv = $rdr->value;
          $out0 .= sprintf "  Cust: Name = %-7s Street = %-12s City =
            $rv[0], $rv[1], $rv[2];
      elsif ($rdr->rx == 1) {
          $out1 .= "  P: ".$rdr->value."\n";

  print "output0:\n$out0\n";
  print "output1:\n$out1\n";

Given the following XML structure as input:

  my $line2 = q{
    <customer name="o'rob" id="444">
      <street>pod alley</street>
      <city>no city</city>
    <customer1 name="troy" id="333">
      <street>one way</street>
      <city>any city</city>
    <tcustomer name="nbc" id="777">
      <customer name='"sue"' id="111">
        <street>baker street</street>
        <customer name="&lt;smith&gt;" id="652">
          <street>high street</street>
        <customer name="&amp;jones" id="184">
          <street>maple street</street>
          <city>new york</city>
        <customer name="stewart" id="520">
          <street>  ring   road   </street>
          <city>  "'&amp;&lt;&#65;&gt;'"  </city>
    <dummy value="ttt">test</dummy>

This is the output:

    Cust: Name = o'rob   Street = pod alley    City = no city
    Cust: Name = "sue"   Street = baker street City = sidney
    Cust: Name = <smith> Street = high street  City = boston
    Cust: Name = &jones  Street = maple street City = new york
    Cust: Name = stewart Street = ring road    City = "'&<A>'"

    P: <p><p>b1</p><p>b2</p></p>
    P: <p>b3</p>

Site Timeline