PushParser
[Raku LibXML Project] / [LibXML-Writer Module] / Writer :: PushParser
class LibXML::Writer::PushParser
LibXML push-parser construction
Synopsis
use LibXML::Writer::PushParser;
use LibXML::SAX::Handler::SAX2;
class SAXShouter is LibXML::SAX::Handler::SAX2 {
use LibXML::SAX::Builder :sax-cb;
method startElement($name, |c) is sax-cb {
nextwith($name.uc, |c);
}
method endElement($name, |c) is sax-cb {
nextwith($name.uc, |c);
}
method characters($chars, |c) is sax-cb {
nextwith($chars.uc, |c);
}
}
my SAXShouter $sax-handler .= new;
my LibXML::Writer::PushParser $writer .= new: :$sax-handler;
$writer.startDocument();
$writer.startElement('Foo');
$writer.startElement('Bar');
$writer.endElement;
$writer.push('<Baz/>');
$writer.endElement;
$writer.endDocument;
my $doc = $writer.finish-push;
say $doc.Str; # <?xml version="1.0" encoding="UTF-8"?><FOO><BAR/><BAZ/></FOO>
Description
This class allows document construction via an externally defined LibXML::PushParser object.
It is most likely to be useful if the XML is to be consumed via a LibXML SAX handler.