20
20
#endif
21
21
22
22
#include "php.h"
23
+
23
24
#if defined(HAVE_LIBXML ) && defined(HAVE_DOM )
24
25
#include "php_dom.h"
25
26
@@ -1001,6 +1002,7 @@ PHP_METHOD(DOMNode, replaceChild)
1001
1002
xmlNodePtr children , newchild , oldchild , nodep ;
1002
1003
dom_object * intern , * newchildobj , * oldchildobj ;
1003
1004
int foundoldchild = 0 , stricterror ;
1005
+ bool replacedoctype = false;
1004
1006
1005
1007
int ret ;
1006
1008
@@ -1063,13 +1065,21 @@ PHP_METHOD(DOMNode, replaceChild)
1063
1065
dom_reconcile_ns (nodep -> doc , newchild );
1064
1066
}
1065
1067
} else if (oldchild != newchild ) {
1068
+ xmlDtdPtr intSubset = xmlGetIntSubset (nodep -> doc );
1069
+ replacedoctype = (intSubset == (xmlDtd * ) oldchild );
1070
+
1066
1071
if (newchild -> doc == NULL && nodep -> doc != NULL ) {
1067
1072
xmlSetTreeDoc (newchild , nodep -> doc );
1068
1073
newchildobj -> document = intern -> document ;
1069
1074
php_libxml_increment_doc_ref ((php_libxml_node_object * )newchildobj , NULL );
1070
1075
}
1076
+
1071
1077
xmlReplaceNode (oldchild , newchild );
1072
1078
dom_reconcile_ns (nodep -> doc , newchild );
1079
+
1080
+ if (replacedoctype ) {
1081
+ nodep -> doc -> intSubset = (xmlDtd * ) newchild ;
1082
+ }
1073
1083
}
1074
1084
DOM_RET_OBJ (oldchild , & ret , intern );
1075
1085
return ;
@@ -1668,7 +1678,7 @@ static void dom_canonicalization(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{
1668
1678
buf = xmlAllocOutputBuffer (NULL );
1669
1679
}
1670
1680
1671
- if (buf != NULL ) {
1681
+ if (buf != NULL ) {
1672
1682
ret = xmlC14NDocSaveTo (docp , nodeset , exclusive , inclusive_ns_prefixes ,
1673
1683
with_comments , buf );
1674
1684
}
@@ -1683,9 +1693,9 @@ static void dom_canonicalization(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{
1683
1693
xmlXPathFreeContext (ctxp );
1684
1694
}
1685
1695
1686
- if (buf == NULL || ret < 0 ) {
1687
- RETVAL_FALSE ;
1688
- } else {
1696
+ if (buf == NULL || ret < 0 ) {
1697
+ RETVAL_FALSE ;
1698
+ } else {
1689
1699
if (mode == 0 ) {
1690
1700
#ifdef LIBXML2_NEW_BUFFER
1691
1701
ret = xmlOutputBufferGetSize (buf );
@@ -1702,7 +1712,7 @@ static void dom_canonicalization(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{
1702
1712
RETVAL_EMPTY_STRING ();
1703
1713
}
1704
1714
}
1705
- }
1715
+ }
1706
1716
1707
1717
if (buf ) {
1708
1718
int bytes ;
0 commit comments