@@ -724,6 +724,83 @@ PHP_METHOD(DOMElement, setAttributeNS)
724
724
}
725
725
/* }}} end dom_element_set_attribute_ns */
726
726
727
+ static void dom_remove_eliminated_ns_single_element (xmlNodePtr node , xmlNsPtr eliminatedNs )
728
+ {
729
+ ZEND_ASSERT (node -> type == XML_ELEMENT_NODE );
730
+ if (node -> ns == eliminatedNs ) {
731
+ node -> ns = NULL ;
732
+ }
733
+
734
+ for (xmlAttrPtr attr = node -> properties ; attr != NULL ; attr = attr -> next ) {
735
+ if (attr -> ns == eliminatedNs ) {
736
+ attr -> ns = NULL ;
737
+ }
738
+ }
739
+ }
740
+
741
+ static void dom_remove_eliminated_ns (xmlNodePtr node , xmlNsPtr eliminatedNs )
742
+ {
743
+ dom_remove_eliminated_ns_single_element (node , eliminatedNs );
744
+
745
+ xmlNodePtr base = node ;
746
+ node = node -> children ;
747
+ while (node != NULL ) {
748
+ ZEND_ASSERT (node != base );
749
+
750
+ if (node -> type == XML_ELEMENT_NODE ) {
751
+ dom_remove_eliminated_ns_single_element (node , eliminatedNs );
752
+
753
+ if (node -> children ) {
754
+ node = node -> children ;
755
+ continue ;
756
+ }
757
+ }
758
+
759
+ if (node -> next ) {
760
+ node = node -> next ;
761
+ } else {
762
+ /* Go upwards, until we find a parent node with a next sibling, or until we hit the base. */
763
+ do {
764
+ node = node -> parent ;
765
+ if (node == base ) {
766
+ return ;
767
+ }
768
+ } while (node -> next == NULL );
769
+ node = node -> next ;
770
+ }
771
+ }
772
+ }
773
+
774
+ static void dom_eliminate_ns (xmlNodePtr nodep , xmlNsPtr nsptr )
775
+ {
776
+ if (nsptr -> href != NULL ) {
777
+ xmlFree ((char * ) nsptr -> href );
778
+ nsptr -> href = NULL ;
779
+ }
780
+ if (nsptr -> prefix != NULL ) {
781
+ xmlFree ((char * ) nsptr -> prefix );
782
+ nsptr -> prefix = NULL ;
783
+ }
784
+
785
+ /* Remove it from the list and move it to the old ns list */
786
+ xmlNsPtr current_ns = nodep -> nsDef ;
787
+ if (current_ns == nsptr ) {
788
+ nodep -> nsDef = nsptr -> next ;
789
+ } else {
790
+ do {
791
+ if (current_ns -> next == nsptr ) {
792
+ current_ns -> next = nsptr -> next ;
793
+ break ;
794
+ }
795
+ current_ns = current_ns -> next ;
796
+ } while (current_ns != NULL );
797
+ }
798
+ nsptr -> next = NULL ;
799
+ dom_set_old_ns (nodep -> doc , nsptr );
800
+
801
+ dom_remove_eliminated_ns (nodep , nsptr );
802
+ }
803
+
727
804
/* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElRemAtNS
728
805
Since: DOM Level 2
729
806
*/
@@ -754,14 +831,7 @@ PHP_METHOD(DOMElement, removeAttributeNS)
754
831
nsptr = dom_get_nsdecl (nodep , (xmlChar * )name );
755
832
if (nsptr != NULL ) {
756
833
if (xmlStrEqual ((xmlChar * )uri , nsptr -> href )) {
757
- if (nsptr -> href != NULL ) {
758
- xmlFree ((char * ) nsptr -> href );
759
- nsptr -> href = NULL ;
760
- }
761
- if (nsptr -> prefix != NULL ) {
762
- xmlFree ((char * ) nsptr -> prefix );
763
- nsptr -> prefix = NULL ;
764
- }
834
+ dom_eliminate_ns (nodep , nsptr );
765
835
} else {
766
836
RETURN_NULL ();
767
837
}
0 commit comments