Commits

Anonymous committed 3f25fe8

fix reconcilation of the "xml" namespace [rt.cpan.org #26450]

Comments (0)

Files changed (4)

 Revision history for Perl extension XML::LibXML
 
+pre1.64
+   - fix reconcilation of the "xml" namespace [rt.cpan.org #26450] 
+
 1.63
    - added no_network parser flag
    - added support for exclusive canonicalization (http://www.w3.org/TR/xml-exc-c14n/)
 /* #define warn(string) fprintf(stderr, string) */
 
 #ifdef XS_WARNINGS
-#define xs_warn(string) warn(string) 
+#define xs_warn(string) warn("%s",string) 
 #else
 #define xs_warn(string)
 #endif
 _domReconcileNsAttr(xmlAttrPtr attr, xmlNsPtr * unused)
 {
         xmlNodePtr tree = attr->parent;
+	if (tree == NULL)
+		return;
         if( attr->ns != NULL )
         {
-                xmlNsPtr ns = xmlSearchNs( tree->doc, tree->parent, attr->ns->prefix );
+		xmlNsPtr ns;
+		if ((attr->ns->prefix != NULL) && 
+		    (xmlStrEqual(attr->ns->prefix, BAD_CAST "xml"))) {
+			/* prefix 'xml' has no visible declaration */
+			ns = xmlSearchNsByHref(tree->doc, tree, XML_XML_NAMESPACE);
+			attr->ns = ns;
+			return;
+		} else {
+			ns = xmlSearchNs( tree->doc, tree->parent, attr->ns->prefix );
+		}
                 if( ns != NULL && ns->href != NULL && attr->ns->href != NULL &&
                     xmlStrcmp(ns->href,attr->ns->href) == 0 )
                 {
                         {
                                 /* Replace/Add the namespace declaration on the element */
                                 attr->ns = xmlCopyNamespace(attr->ns);
-                                domAddNsDef(tree, attr->ns);
+				if (attr->ns) {
+				  domAddNsDef(tree, attr->ns);
+				}
                         }
                 }
         }
  * for warn!!
  */
 #ifdef XS_WARNINGS
-#define xs_warn(string) warn(string) 
+#define xs_warn(string) warn("%s",string) 
 #else
 #define xs_warn(string)
 #endif
 # -*- cperl -*-
 use Test;
-BEGIN { plan tests=>122; }
+BEGIN { plan tests=>124; }
 use XML::LibXML;
 use XML::LibXML::Common qw(:libxml);
 
 	ok ( !defined($child->getAttribute( 'xmlns:other' )) );
 	ok ( defined($doca->documentElement->getAttribute( 'xmlns:other' )) );
 }
+
+print "# 10. xml namespace\n";
+{
+  my $docOne = XML::LibXML->new->parse_string('<foo><inc xml:id="test"/></foo>');
+  my $docTwo = XML::LibXML->new->parse_string('<bar><urgh xml:id="foo"/></bar>');
+
+  my $inc = $docOne->getElementById('test');
+  my $rep = $docTwo->getElementById('foo');
+  $inc->parentNode->replaceChild($rep, $inc);
+  ok($inc->getAttributeNS('http://www.w3.org/XML/1998/namespace','id'),'test');
+  ok($inc->isSameNode($docOne->getElementById('test')));
+}