ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-xml
perl-xml
XML::SAX::Writer end_element does not follow SAX2 spec
by Dave Rolsky other posts by this author
Jan 16 2004 7:58PM messages near this date
view in the new Beta List Site
segmentation fault | XML::LibXML failing threads test
The SAX2 spec says the following about the end_element event:

  element is a hash with these properties:

      Name 	The element type name (including prefix).

  If namespace processing is turned on (which is the default), these
  properties are also available:

      NamespaceURI 	The namespace of this element.
      Prefix    	The namespace prefix used on this element.
      LocalName 	The local name of this element.

So if namespace processing is on, I would expect that I'd be able to
simply pass the latter 3 values, and not pass Name at all.

Unfortunately, XML::SAX::Writer::XML ignores all this, and only looks
for Name!

Even worse, I'm looking at the tests, and there are very few tests,
and most of the actual XML-generating methods are not tested at all.

Anyway, there's a patch below my sig for end_element.


-dave

/*=======================
House Absolute Consulting
www.houseabsolute.com
=======================*/

diff -ru ../XML-SAX-Writer-0.44/lib/XML/SAX/Writer/XML.pm ./lib/XML/SAX/Writer/XML.pm
--- ../XML-SAX-Writer-0.44/lib/XML/SAX/Writer/XML.pm	2002-07-06 12:49:06.000000000 -0500
+++ ./lib/XML/SAX/Writer/XML.pm	2004-01-16 13:56:55.000000000 -0600
@@ -54,19 +54,7 @@
     $self-> _output_element;
     my $attr = $data-> {Attributes};

-    # fix the namespaces and prefixes of what we're receiving, in case
-    # something is wrong
-    if ($data-> {NamespaceURI}) {
-        my $uri = $self-> {NSHelper}->getURI($data->{Prefix}) || '';
-        if ($uri ne $data-> {NamespaceURI}) { # ns has precedence
-            $data-> {Prefix} = $self->{NSHelper}->getPrefix($data->{NamespaceURI}); # random
, but correct
-            $data-> {Name} = $data->{Prefix} ? "$data->{Prefix}:$data->{LocalName}" : "$data
-> {LocalName}";
-        }
-    }
-    elsif ($data-> {Prefix}) { # we can't have a prefix and no NS
-        $data-> {Name}   = $data->{LocalName};
-        $data-> {Prefix} = '';
-    }
+    $self-> _clean_element_data($data);

     # create a hash containing the attributes so that we can ensure there is
     # no duplication. Also, we check that ns are properly declared, that the
@@ -122,6 +110,7 @@
         $el = $self-> {BufferElement} . ' />';
     }
     else {
+        $self-> _clean_element_data($data);
         $el = '</' . $data-> {Name} . '>';
     }
     $el = $self-> {Encoder}->convert($el);
@@ -131,6 +120,25 @@
 }
 #-------------------------------------------------------------------#

+sub _clean_element_data {
+    my $self = shift;
+    my $data = shift;
+
+    # fix the namespaces and prefixes of what we're receiving, in case
+    # something is wrong
+    if ($data-> {NamespaceURI}) {
+        my $uri = $self-> {NSHelper}->getURI($data->{Prefix}) || '';
+        if ($uri ne $data-> {NamespaceURI}) { # ns has precedence
+            $data-> {Prefix} = $self->{NSHelper}->getPrefix($data->{NamespaceURI}); # random
, but correct
+            $data-> {Name} = $data->{Prefix} ? "$data->{Prefix}:$data->{LocalName}" : "$data
-> {LocalName}";
+        }
+    }
+    elsif ($data-> {Prefix}) { # we can't have a prefix and no NS
+        $data-> {Name}   = $data->{LocalName};
+        $data-> {Prefix} = '';
+    }
+}
+
 #-------------------------------------------------------------------#
 # characters
 #-------------------------------------------------------------------#

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved