File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -1518,20 +1518,33 @@ NAMESPACE_ERR: Raised if
1518
1518
xmlNsPtr dom_get_ns (xmlNodePtr nodep , char * uri , int * errorcode , char * prefix ) {
1519
1519
xmlNsPtr nsptr = NULL ;
1520
1520
1521
- * errorcode = 0 ;
1522
-
1523
1521
if (! ((prefix && !strcmp (prefix , "xml" ) && strcmp (uri , (char * )XML_XML_NAMESPACE )) ||
1524
1522
(prefix && !strcmp (prefix , "xmlns" ) && strcmp (uri , (char * )DOM_XMLNS_NAMESPACE )) ||
1525
1523
(prefix && !strcmp (uri , (char * )DOM_XMLNS_NAMESPACE ) && strcmp (prefix , "xmlns" )))) {
1524
+ /* Reuse the old namespaces from doc->oldNs if possible, before creating a new one */
1525
+ xmlDocPtr doc = nodep -> doc ;
1526
+ if (doc && doc -> oldNs != NULL ) {
1527
+ xmlNsPtr cur = doc -> oldNs ;
1528
+ do {
1529
+ if (xmlStrEqual (cur -> prefix , (xmlChar * )prefix ) && xmlStrEqual (cur -> href , (xmlChar * )uri )) {
1530
+ nsptr = cur ;
1531
+ goto out ;
1532
+ }
1533
+ cur = cur -> next ;
1534
+ } while (cur );
1535
+ }
1536
+ /* Couldn't reuse one, create a new one. */
1526
1537
nsptr = xmlNewNs (nodep , (xmlChar * )uri , (xmlChar * )prefix );
1527
1538
}
1528
1539
1529
1540
if (nsptr == NULL ) {
1530
1541
* errorcode = NAMESPACE_ERR ;
1542
+ return NULL ;
1531
1543
}
1532
1544
1545
+ out :
1546
+ * errorcode = 0 ;
1533
1547
return nsptr ;
1534
-
1535
1548
}
1536
1549
/* }}} end dom_get_ns */
1537
1550
You can’t perform that action at this time.
0 commit comments