Subject: | Adding XML::SAX::DocumentLocator support to XML::LibXML::SAX::Parser |
MIME-Version: | 1.0 |
X-Mailer: | MIME-tools 5.418 (Entity 5.418) |
X-RT-Original-Encoding: | utf-8 |
Content-Type: | multipart/mixed; boundary="----------=_1187654509-14634-1" |
Content-Length: | 0 |
Content-Type: | text/plain; charset="utf8" |
Content-Disposition: | inline |
Content-Transfer-Encoding: | binary |
Content-Length: | 248 |
The XML::LibXML::SAX::Parser module doesn't really support
XML::SAX::DocumentLocator. The attached patch is my stab at adding that
support. If it looks good, I hope that it will be considered for
inclusion in XML::LibXML. Thanks!
--
David Hull
Subject: | Parser.pm.diff |
MIME-Version: | 1.0 |
Content-Type: | multipart/mixed; boundary="----------=_1187654509-14634-0" |
X-Mailer: | MIME-tools 5.418 (Entity 5.418) |
Content-Length: | 0 |
Content-Type: | text/plain; charset="utf8" |
Content-Disposition: | inline |
Content-Transfer-Encoding: | binary |
X-RT-Original-Encoding: | utf-8 |
Content-Length: | 0 |
Content-Type: | text/x-patch; name="Parser.pm.diff" |
Content-Disposition: | inline; filename="Parser.pm.diff" |
Content-Transfer-Encoding: | binary |
X-RT-Original-Encoding: | ascii |
Content-Length: | 1295 |
--- lib/XML/LibXML/SAX/Parser.pm.orig 2007-08-20 16:25:04.000000000 -0700
+++ lib/XML/LibXML/SAX/Parser.pm 2007-08-20 16:26:31.000000000 -0700
@@ -43,6 +43,21 @@
my $self = shift;
my ($node) = @_;
+ $self->{node_stack} = [];
+ my $doc = $node->ownerDocument();
+ my $dtd = defined $doc ? $doc->externalSubset() : undef;
+
+ $self->set_document_locator(
+ XML::SAX::DocumentLocator->new(
+ sub { defined $dtd ? $dtd->publicId() : undef },
+ sub { defined $dtd ? $dtd->systemId() : undef },
+ sub { $self->{node_stack}->[$#{$self->{node_stack}}]->line_number() },
+ sub { 1 },
+ sub { defined $doc ? $doc->encoding() : undef },
+ sub { defined $doc ? $doc->version() : undef},
+ ),
+ );
+
if ( $node->nodeType() == XML_DOCUMENT_NODE
|| $node->nodeType == XML_HTML_DOCUMENT_NODE ) {
$self->start_document({});
@@ -55,6 +70,8 @@
sub process_node {
my ($self, $node) = @_;
+ push(@{$self->{node_stack}}, $node);
+
my $node_type = $node->nodeType();
if ($node_type == XML_COMMENT_NODE) {
$self->comment( { Data => $node->getData } );
@@ -102,6 +119,8 @@
else {
# warn("unsupported node type: $node_type");
}
+
+ pop(@{$self->{node_stack}});
}
sub process_element {