How to embed events in XML :: SAX :: Pipeline

I have a SAX filter that wants to insert some content into the current stream for downstream handlers to process (i.e.: add node to the output). How can I do that? I was thinking, maybe I could create a new pipeline (connected to $self) and call parse_string()on it, but this did not work:

Trying to pop context without push context at /usr/lib/perl5/vendor_perl/5.10/XML/NamespaceSupport.pm

The handler looks something like this:

package My::Filter;
use base qw(XML::SAX::Base);

sub end_element {
  my $self = shift;

  if($insertStuff) {
    # WHAT TO DO HERE? 
    # This doesn't work
    XML::SAX::ParserFactory->parser( Handler => $self)->parse_string("<new>content</new>");
  }

  $self->SUPER::start_element($element); 
}
+3
source share

Source: https://habr.com/ru/post/1773292/


All Articles