document.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2018 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Christian Stocker <chregu@php.net> |
  16. | Rob Richards <rrichards@php.net> |
  17. +----------------------------------------------------------------------+
  18. */
  19. #ifdef HAVE_CONFIG_H
  20. #include "config.h"
  21. #endif
  22. #include "php.h"
  23. #if HAVE_LIBXML && HAVE_DOM
  24. #include "php_dom.h"
  25. #include <libxml/SAX.h>
  26. #ifdef LIBXML_SCHEMAS_ENABLED
  27. #include <libxml/relaxng.h>
  28. #include <libxml/xmlschemas.h>
  29. #endif
  30. typedef struct _idsIterator idsIterator;
  31. struct _idsIterator {
  32. xmlChar *elementId;
  33. xmlNode *element;
  34. };
  35. #define DOM_LOAD_STRING 0
  36. #define DOM_LOAD_FILE 1
  37. /* {{{ arginfo */
  38. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_element, 0, 0, 1)
  39. ZEND_ARG_INFO(0, tagName)
  40. ZEND_ARG_INFO(0, value)
  41. ZEND_END_ARG_INFO();
  42. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_document_fragment, 0, 0, 0)
  43. ZEND_END_ARG_INFO();
  44. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_text_node, 0, 0, 1)
  45. ZEND_ARG_INFO(0, data)
  46. ZEND_END_ARG_INFO();
  47. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_comment, 0, 0, 1)
  48. ZEND_ARG_INFO(0, data)
  49. ZEND_END_ARG_INFO();
  50. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_cdatasection, 0, 0, 1)
  51. ZEND_ARG_INFO(0, data)
  52. ZEND_END_ARG_INFO();
  53. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_processing_instruction, 0, 0, 2)
  54. ZEND_ARG_INFO(0, target)
  55. ZEND_ARG_INFO(0, data)
  56. ZEND_END_ARG_INFO();
  57. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_attribute, 0, 0, 1)
  58. ZEND_ARG_INFO(0, name)
  59. ZEND_END_ARG_INFO();
  60. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_entity_reference, 0, 0, 1)
  61. ZEND_ARG_INFO(0, name)
  62. ZEND_END_ARG_INFO();
  63. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_get_elements_by_tag_name, 0, 0, 1)
  64. ZEND_ARG_INFO(0, tagName)
  65. ZEND_END_ARG_INFO();
  66. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_import_node, 0, 0, 2)
  67. ZEND_ARG_OBJ_INFO(0, importedNode, DOMNode, 0)
  68. ZEND_ARG_INFO(0, deep)
  69. ZEND_END_ARG_INFO();
  70. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_element_ns, 0, 0, 2)
  71. ZEND_ARG_INFO(0, namespaceURI)
  72. ZEND_ARG_INFO(0, qualifiedName)
  73. ZEND_ARG_INFO(0, value)
  74. ZEND_END_ARG_INFO();
  75. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_attribute_ns, 0, 0, 2)
  76. ZEND_ARG_INFO(0, namespaceURI)
  77. ZEND_ARG_INFO(0, qualifiedName)
  78. ZEND_END_ARG_INFO();
  79. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_get_elements_by_tag_name_ns, 0, 0, 2)
  80. ZEND_ARG_INFO(0, namespaceURI)
  81. ZEND_ARG_INFO(0, localName)
  82. ZEND_END_ARG_INFO();
  83. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_get_element_by_id, 0, 0, 1)
  84. ZEND_ARG_INFO(0, elementId)
  85. ZEND_END_ARG_INFO();
  86. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_adopt_node, 0, 0, 1)
  87. ZEND_ARG_OBJ_INFO(0, source, DOMNode, 0)
  88. ZEND_END_ARG_INFO();
  89. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_normalize_document, 0, 0, 0)
  90. ZEND_END_ARG_INFO();
  91. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_rename_node, 0, 0, 3)
  92. ZEND_ARG_OBJ_INFO(0, node, DOMNode, 0)
  93. ZEND_ARG_INFO(0, namespaceURI)
  94. ZEND_ARG_INFO(0, qualifiedName)
  95. ZEND_END_ARG_INFO();
  96. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_load, 0, 0, 1)
  97. ZEND_ARG_INFO(0, source)
  98. ZEND_ARG_INFO(0, options)
  99. ZEND_END_ARG_INFO();
  100. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_save, 0, 0, 1)
  101. ZEND_ARG_INFO(0, file)
  102. ZEND_END_ARG_INFO();
  103. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_loadxml, 0, 0, 1)
  104. ZEND_ARG_INFO(0, source)
  105. ZEND_ARG_INFO(0, options)
  106. ZEND_END_ARG_INFO();
  107. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_savexml, 0, 0, 0)
  108. ZEND_ARG_OBJ_INFO(0, node, DOMNode, 1)
  109. ZEND_ARG_INFO(0, options)
  110. ZEND_END_ARG_INFO();
  111. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_construct, 0, 0, 0)
  112. ZEND_ARG_INFO(0, version)
  113. ZEND_ARG_INFO(0, encoding)
  114. ZEND_END_ARG_INFO();
  115. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_validate, 0, 0, 0)
  116. ZEND_END_ARG_INFO();
  117. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_xinclude, 0, 0, 0)
  118. ZEND_ARG_INFO(0, options)
  119. ZEND_END_ARG_INFO();
  120. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_loadhtml, 0, 0, 1)
  121. ZEND_ARG_INFO(0, source)
  122. ZEND_ARG_INFO(0, options)
  123. ZEND_END_ARG_INFO();
  124. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_loadhtmlfile, 0, 0, 1)
  125. ZEND_ARG_INFO(0, source)
  126. ZEND_ARG_INFO(0, options)
  127. ZEND_END_ARG_INFO();
  128. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_savehtml, 0, 0, 0)
  129. ZEND_END_ARG_INFO();
  130. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_savehtmlfile, 0, 0, 1)
  131. ZEND_ARG_INFO(0, file)
  132. ZEND_END_ARG_INFO();
  133. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_schema_validate_file, 0, 0, 1)
  134. ZEND_ARG_INFO(0, filename)
  135. ZEND_END_ARG_INFO();
  136. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_schema_validate_xml, 0, 0, 1)
  137. ZEND_ARG_INFO(0, source)
  138. ZEND_END_ARG_INFO();
  139. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_relaxNG_validate_file, 0, 0, 1)
  140. ZEND_ARG_INFO(0, filename)
  141. ZEND_END_ARG_INFO();
  142. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_relaxNG_validate_xml, 0, 0, 1)
  143. ZEND_ARG_INFO(0, source)
  144. ZEND_END_ARG_INFO();
  145. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_registernodeclass, 0, 0, 2)
  146. ZEND_ARG_INFO(0, baseClass)
  147. ZEND_ARG_INFO(0, extendedClass)
  148. ZEND_END_ARG_INFO();
  149. /* }}} */
  150. /*
  151. * class DOMDocument extends DOMNode
  152. *
  153. * URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-i-Document
  154. * Since:
  155. */
  156. const zend_function_entry php_dom_document_class_functions[] = { /* {{{ */
  157. PHP_FALIAS(createElement, dom_document_create_element, arginfo_dom_document_create_element)
  158. PHP_FALIAS(createDocumentFragment, dom_document_create_document_fragment, arginfo_dom_document_create_document_fragment)
  159. PHP_FALIAS(createTextNode, dom_document_create_text_node, arginfo_dom_document_create_text_node)
  160. PHP_FALIAS(createComment, dom_document_create_comment, arginfo_dom_document_create_comment)
  161. PHP_FALIAS(createCDATASection, dom_document_create_cdatasection, arginfo_dom_document_create_cdatasection)
  162. PHP_FALIAS(createProcessingInstruction, dom_document_create_processing_instruction, arginfo_dom_document_create_processing_instruction)
  163. PHP_FALIAS(createAttribute, dom_document_create_attribute, arginfo_dom_document_create_attribute)
  164. PHP_FALIAS(createEntityReference, dom_document_create_entity_reference, arginfo_dom_document_create_entity_reference)
  165. PHP_FALIAS(getElementsByTagName, dom_document_get_elements_by_tag_name, arginfo_dom_document_get_elements_by_tag_name)
  166. PHP_FALIAS(importNode, dom_document_import_node, arginfo_dom_document_import_node)
  167. PHP_FALIAS(createElementNS, dom_document_create_element_ns, arginfo_dom_document_create_element_ns)
  168. PHP_FALIAS(createAttributeNS, dom_document_create_attribute_ns, arginfo_dom_document_create_attribute_ns)
  169. PHP_FALIAS(getElementsByTagNameNS, dom_document_get_elements_by_tag_name_ns, arginfo_dom_document_get_elements_by_tag_name_ns)
  170. PHP_FALIAS(getElementById, dom_document_get_element_by_id, arginfo_dom_document_get_element_by_id)
  171. PHP_FALIAS(adoptNode, dom_document_adopt_node, arginfo_dom_document_adopt_node)
  172. PHP_FALIAS(normalizeDocument, dom_document_normalize_document, arginfo_dom_document_normalize_document)
  173. PHP_FALIAS(renameNode, dom_document_rename_node, arginfo_dom_document_rename_node)
  174. PHP_ME(domdocument, load, arginfo_dom_document_load, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
  175. PHP_FALIAS(save, dom_document_save, arginfo_dom_document_save)
  176. PHP_ME(domdocument, loadXML, arginfo_dom_document_loadxml, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
  177. PHP_FALIAS(saveXML, dom_document_savexml, arginfo_dom_document_savexml)
  178. PHP_ME(domdocument, __construct, arginfo_dom_document_construct, ZEND_ACC_PUBLIC)
  179. PHP_FALIAS(validate, dom_document_validate, arginfo_dom_document_validate)
  180. PHP_FALIAS(xinclude, dom_document_xinclude, arginfo_dom_document_xinclude)
  181. #if defined(LIBXML_HTML_ENABLED)
  182. PHP_ME(domdocument, loadHTML, arginfo_dom_document_loadhtml, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
  183. PHP_ME(domdocument, loadHTMLFile, arginfo_dom_document_loadhtmlfile, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
  184. PHP_FALIAS(saveHTML, dom_document_save_html, arginfo_dom_document_savehtml)
  185. PHP_FALIAS(saveHTMLFile, dom_document_save_html_file, arginfo_dom_document_savehtmlfile)
  186. #endif /* defined(LIBXML_HTML_ENABLED) */
  187. #if defined(LIBXML_SCHEMAS_ENABLED)
  188. PHP_FALIAS(schemaValidate, dom_document_schema_validate_file, arginfo_dom_document_schema_validate_file)
  189. PHP_FALIAS(schemaValidateSource, dom_document_schema_validate_xml, arginfo_dom_document_schema_validate_xml)
  190. PHP_FALIAS(relaxNGValidate, dom_document_relaxNG_validate_file, arginfo_dom_document_relaxNG_validate_file)
  191. PHP_FALIAS(relaxNGValidateSource, dom_document_relaxNG_validate_xml, arginfo_dom_document_relaxNG_validate_xml)
  192. #endif
  193. PHP_ME(domdocument, registerNodeClass, arginfo_dom_document_registernodeclass, ZEND_ACC_PUBLIC)
  194. PHP_FE_END
  195. };
  196. /* }}} */
  197. /* {{{ docType DOMDocumentType
  198. readonly=yes
  199. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-B63ED1A31
  200. Since:
  201. */
  202. int dom_document_doctype_read(dom_object *obj, zval *retval)
  203. {
  204. xmlDoc *docp = (xmlDocPtr) dom_object_get_node(obj);
  205. xmlDtdPtr dtdptr;
  206. if (docp == NULL) {
  207. php_dom_throw_error(INVALID_STATE_ERR, 0);
  208. return FAILURE;
  209. }
  210. dtdptr = xmlGetIntSubset(docp);
  211. if (!dtdptr) {
  212. ZVAL_NULL(retval);
  213. return SUCCESS;
  214. }
  215. php_dom_create_object((xmlNodePtr) dtdptr, retval, obj);
  216. return SUCCESS;
  217. }
  218. /* }}} */
  219. /* {{{ implementation DOMImplementation
  220. readonly=yes
  221. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1B793EBA
  222. Since:
  223. */
  224. int dom_document_implementation_read(dom_object *obj, zval *retval)
  225. {
  226. php_dom_create_implementation(retval);
  227. return SUCCESS;
  228. }
  229. /* }}} */
  230. /* {{{ documentElement DOMElement
  231. readonly=yes
  232. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-87CD092
  233. Since:
  234. */
  235. int dom_document_document_element_read(dom_object *obj, zval *retval)
  236. {
  237. xmlDoc *docp = (xmlDocPtr) dom_object_get_node(obj);
  238. xmlNode *root;
  239. if (docp == NULL) {
  240. php_dom_throw_error(INVALID_STATE_ERR, 0);
  241. return FAILURE;
  242. }
  243. root = xmlDocGetRootElement(docp);
  244. if (!root) {
  245. ZVAL_NULL(retval);
  246. return SUCCESS;
  247. }
  248. php_dom_create_object(root, retval, obj);
  249. return SUCCESS;
  250. }
  251. /* }}} */
  252. /* {{{ encoding string
  253. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-encoding
  254. Since: DOM Level 3
  255. */
  256. int dom_document_encoding_read(dom_object *obj, zval *retval)
  257. {
  258. xmlDoc *docp = (xmlDocPtr) dom_object_get_node(obj);
  259. char *encoding;
  260. if (docp == NULL) {
  261. php_dom_throw_error(INVALID_STATE_ERR, 0);
  262. return FAILURE;
  263. }
  264. encoding = (char *) docp->encoding;
  265. if (encoding != NULL) {
  266. ZVAL_STRING(retval, encoding);
  267. } else {
  268. ZVAL_NULL(retval);
  269. }
  270. return SUCCESS;
  271. }
  272. int dom_document_encoding_write(dom_object *obj, zval *newval)
  273. {
  274. xmlDoc *docp = (xmlDocPtr) dom_object_get_node(obj);
  275. zend_string *str;
  276. xmlCharEncodingHandlerPtr handler;
  277. if (docp == NULL) {
  278. php_dom_throw_error(INVALID_STATE_ERR, 0);
  279. return FAILURE;
  280. }
  281. str = zval_get_string(newval);
  282. handler = xmlFindCharEncodingHandler(ZSTR_VAL(str));
  283. if (handler != NULL) {
  284. xmlCharEncCloseFunc(handler);
  285. if (docp->encoding != NULL) {
  286. xmlFree((xmlChar *)docp->encoding);
  287. }
  288. docp->encoding = xmlStrdup((const xmlChar *) ZSTR_VAL(str));
  289. } else {
  290. php_error_docref(NULL, E_WARNING, "Invalid Document Encoding");
  291. }
  292. zend_string_release_ex(str, 0);
  293. return SUCCESS;
  294. }
  295. /* }}} */
  296. /* {{{ standalone boolean
  297. readonly=no
  298. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-standalone
  299. Since: DOM Level 3
  300. */
  301. int dom_document_standalone_read(dom_object *obj, zval *retval)
  302. {
  303. xmlDoc *docp;
  304. docp = (xmlDocPtr) dom_object_get_node(obj);
  305. if (docp == NULL) {
  306. php_dom_throw_error(INVALID_STATE_ERR, 0);
  307. return FAILURE;
  308. }
  309. ZVAL_BOOL(retval, docp->standalone);
  310. return SUCCESS;
  311. }
  312. int dom_document_standalone_write(dom_object *obj, zval *newval)
  313. {
  314. xmlDoc *docp = (xmlDocPtr) dom_object_get_node(obj);
  315. zend_long standalone;
  316. if (docp == NULL) {
  317. php_dom_throw_error(INVALID_STATE_ERR, 0);
  318. return FAILURE;
  319. }
  320. standalone = zval_get_long(newval);
  321. docp->standalone = ZEND_NORMALIZE_BOOL(standalone);
  322. return SUCCESS;
  323. }
  324. /* }}} */
  325. /* {{{ version string
  326. readonly=no
  327. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-version
  328. Since: DOM Level 3
  329. */
  330. int dom_document_version_read(dom_object *obj, zval *retval)
  331. {
  332. xmlDoc *docp = (xmlDocPtr) dom_object_get_node(obj);
  333. char *version;
  334. if (docp == NULL) {
  335. php_dom_throw_error(INVALID_STATE_ERR, 0);
  336. return FAILURE;
  337. }
  338. version = (char *) docp->version;
  339. if (version != NULL) {
  340. ZVAL_STRING(retval, version);
  341. } else {
  342. ZVAL_NULL(retval);
  343. }
  344. return SUCCESS;
  345. }
  346. int dom_document_version_write(dom_object *obj, zval *newval)
  347. {
  348. xmlDoc *docp = (xmlDocPtr) dom_object_get_node(obj);
  349. zend_string *str;
  350. if (docp == NULL) {
  351. php_dom_throw_error(INVALID_STATE_ERR, 0);
  352. return FAILURE;
  353. }
  354. if (docp->version != NULL) {
  355. xmlFree((xmlChar *) docp->version );
  356. }
  357. str = zval_get_string(newval);
  358. docp->version = xmlStrdup((const xmlChar *) ZSTR_VAL(str));
  359. zend_string_release_ex(str, 0);
  360. return SUCCESS;
  361. }
  362. /* }}} */
  363. /* {{{ strictErrorChecking boolean
  364. readonly=no
  365. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-strictErrorChecking
  366. Since: DOM Level 3
  367. */
  368. int dom_document_strict_error_checking_read(dom_object *obj, zval *retval)
  369. {
  370. if (obj->document) {
  371. dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
  372. ZVAL_BOOL(retval, doc_prop->stricterror);
  373. } else {
  374. ZVAL_FALSE(retval);
  375. }
  376. return SUCCESS;
  377. }
  378. int dom_document_strict_error_checking_write(dom_object *obj, zval *newval)
  379. {
  380. if (obj->document) {
  381. dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
  382. doc_prop->stricterror = zend_is_true(newval);
  383. }
  384. return SUCCESS;
  385. }
  386. /* }}} */
  387. /* {{{ formatOutput boolean
  388. readonly=no
  389. */
  390. int dom_document_format_output_read(dom_object *obj, zval *retval)
  391. {
  392. if (obj->document) {
  393. dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
  394. ZVAL_BOOL(retval, doc_prop->formatoutput);
  395. } else {
  396. ZVAL_FALSE(retval);
  397. }
  398. return SUCCESS;
  399. }
  400. int dom_document_format_output_write(dom_object *obj, zval *newval)
  401. {
  402. if (obj->document) {
  403. dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
  404. doc_prop->formatoutput = zend_is_true(newval);
  405. }
  406. return SUCCESS;
  407. }
  408. /* }}} */
  409. /* {{{ validateOnParse boolean
  410. readonly=no
  411. */
  412. int dom_document_validate_on_parse_read(dom_object *obj, zval *retval)
  413. {
  414. if (obj->document) {
  415. dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
  416. ZVAL_BOOL(retval, doc_prop->validateonparse);
  417. } else {
  418. ZVAL_FALSE(retval);
  419. }
  420. return SUCCESS;
  421. }
  422. int dom_document_validate_on_parse_write(dom_object *obj, zval *newval)
  423. {
  424. if (obj->document) {
  425. dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
  426. doc_prop->validateonparse = zend_is_true(newval);
  427. }
  428. return SUCCESS;
  429. }
  430. /* }}} */
  431. /* {{{ resolveExternals boolean
  432. readonly=no
  433. */
  434. int dom_document_resolve_externals_read(dom_object *obj, zval *retval)
  435. {
  436. if (obj->document) {
  437. dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
  438. ZVAL_BOOL(retval, doc_prop->resolveexternals);
  439. } else {
  440. ZVAL_FALSE(retval);
  441. }
  442. return SUCCESS;
  443. }
  444. int dom_document_resolve_externals_write(dom_object *obj, zval *newval)
  445. {
  446. if (obj->document) {
  447. dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
  448. doc_prop->resolveexternals = zend_is_true(newval);
  449. }
  450. return SUCCESS;
  451. }
  452. /* }}} */
  453. /* {{{ preserveWhiteSpace boolean
  454. readonly=no
  455. */
  456. int dom_document_preserve_whitespace_read(dom_object *obj, zval *retval)
  457. {
  458. if (obj->document) {
  459. dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
  460. ZVAL_BOOL(retval, doc_prop->preservewhitespace);
  461. } else {
  462. ZVAL_FALSE(retval);
  463. }
  464. return SUCCESS;
  465. }
  466. int dom_document_preserve_whitespace_write(dom_object *obj, zval *newval)
  467. {
  468. if (obj->document) {
  469. dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
  470. doc_prop->preservewhitespace = zend_is_true(newval);
  471. }
  472. return SUCCESS;
  473. }
  474. /* }}} */
  475. /* {{{ recover boolean
  476. readonly=no
  477. */
  478. int dom_document_recover_read(dom_object *obj, zval *retval)
  479. {
  480. if (obj->document) {
  481. dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
  482. ZVAL_BOOL(retval, doc_prop->recover);
  483. } else {
  484. ZVAL_FALSE(retval);
  485. }
  486. return SUCCESS;
  487. }
  488. int dom_document_recover_write(dom_object *obj, zval *newval)
  489. {
  490. if (obj->document) {
  491. dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
  492. doc_prop->recover = zend_is_true(newval);
  493. }
  494. return SUCCESS;
  495. }
  496. /* }}} */
  497. /* {{{ substituteEntities boolean
  498. readonly=no
  499. */
  500. int dom_document_substitue_entities_read(dom_object *obj, zval *retval)
  501. {
  502. if (obj->document) {
  503. dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
  504. ZVAL_BOOL(retval, doc_prop->substituteentities);
  505. } else {
  506. ZVAL_FALSE(retval);
  507. }
  508. return SUCCESS;
  509. }
  510. int dom_document_substitue_entities_write(dom_object *obj, zval *newval)
  511. {
  512. if (obj->document) {
  513. dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
  514. doc_prop->substituteentities = zend_is_true(newval);
  515. }
  516. return SUCCESS;
  517. }
  518. /* }}} */
  519. /* {{{ documentURI string
  520. readonly=no
  521. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-documentURI
  522. Since: DOM Level 3
  523. */
  524. int dom_document_document_uri_read(dom_object *obj, zval *retval)
  525. {
  526. xmlDoc *docp = (xmlDocPtr) dom_object_get_node(obj);
  527. char *url;
  528. if (docp == NULL) {
  529. php_dom_throw_error(INVALID_STATE_ERR, 0);
  530. return FAILURE;
  531. }
  532. url = (char *) docp->URL;
  533. if (url != NULL) {
  534. ZVAL_STRING(retval, url);
  535. } else {
  536. ZVAL_NULL(retval);
  537. }
  538. return SUCCESS;
  539. }
  540. int dom_document_document_uri_write(dom_object *obj, zval *newval)
  541. {
  542. xmlDoc *docp = (xmlDocPtr) dom_object_get_node(obj);
  543. zend_string *str;
  544. if (docp == NULL) {
  545. php_dom_throw_error(INVALID_STATE_ERR, 0);
  546. return FAILURE;
  547. }
  548. if (docp->URL != NULL) {
  549. xmlFree((xmlChar *) docp->URL);
  550. }
  551. str = zval_get_string(newval);
  552. docp->URL = xmlStrdup((const xmlChar *) ZSTR_VAL(str));
  553. zend_string_release_ex(str, 0);
  554. return SUCCESS;
  555. }
  556. /* }}} */
  557. /* {{{ config DOMConfiguration
  558. readonly=yes
  559. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-config
  560. Since: DOM Level 3
  561. */
  562. int dom_document_config_read(dom_object *obj, zval *retval)
  563. {
  564. ZVAL_NULL(retval);
  565. return SUCCESS;
  566. }
  567. /* }}} */
  568. /* {{{ proto DOMElement dom_document_create_element(string tagName [, string value])
  569. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-2141741547
  570. Since:
  571. */
  572. PHP_FUNCTION(dom_document_create_element)
  573. {
  574. zval *id;
  575. xmlNode *node;
  576. xmlDocPtr docp;
  577. dom_object *intern;
  578. int ret;
  579. size_t name_len, value_len;
  580. char *name, *value = NULL;
  581. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os|s", &id, dom_document_class_entry, &name, &name_len, &value, &value_len) == FAILURE) {
  582. return;
  583. }
  584. DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
  585. if (xmlValidateName((xmlChar *) name, 0) != 0) {
  586. php_dom_throw_error(INVALID_CHARACTER_ERR, dom_get_strict_error(intern->document));
  587. RETURN_FALSE;
  588. }
  589. node = xmlNewDocNode(docp, NULL, (xmlChar *) name, (xmlChar *) value);
  590. if (!node) {
  591. RETURN_FALSE;
  592. }
  593. DOM_RET_OBJ(node, &ret, intern);
  594. }
  595. /* }}} end dom_document_create_element */
  596. /* {{{ proto DOMDocumentFragment dom_document_create_document_fragment()
  597. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-35CB04B5
  598. Since:
  599. */
  600. PHP_FUNCTION(dom_document_create_document_fragment)
  601. {
  602. zval *id;
  603. xmlNode *node;
  604. xmlDocPtr docp;
  605. dom_object *intern;
  606. int ret;
  607. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &id, dom_document_class_entry) == FAILURE) {
  608. return;
  609. }
  610. DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
  611. node = xmlNewDocFragment(docp);
  612. if (!node) {
  613. RETURN_FALSE;
  614. }
  615. DOM_RET_OBJ(node, &ret, intern);
  616. }
  617. /* }}} end dom_document_create_document_fragment */
  618. /* {{{ proto DOMText dom_document_create_text_node(string data)
  619. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1975348127
  620. Since:
  621. */
  622. PHP_FUNCTION(dom_document_create_text_node)
  623. {
  624. zval *id;
  625. xmlNode *node;
  626. xmlDocPtr docp;
  627. int ret;
  628. size_t value_len;
  629. dom_object *intern;
  630. char *value;
  631. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &id, dom_document_class_entry, &value, &value_len) == FAILURE) {
  632. return;
  633. }
  634. DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
  635. node = xmlNewDocText(docp, (xmlChar *) value);
  636. if (!node) {
  637. RETURN_FALSE;
  638. }
  639. DOM_RET_OBJ(node, &ret, intern);
  640. }
  641. /* }}} end dom_document_create_text_node */
  642. /* {{{ proto DOMComment dom_document_create_comment(string data)
  643. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1334481328
  644. Since:
  645. */
  646. PHP_FUNCTION(dom_document_create_comment)
  647. {
  648. zval *id;
  649. xmlNode *node;
  650. xmlDocPtr docp;
  651. int ret;
  652. size_t value_len;
  653. dom_object *intern;
  654. char *value;
  655. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &id, dom_document_class_entry, &value, &value_len) == FAILURE) {
  656. return;
  657. }
  658. DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
  659. node = xmlNewDocComment(docp, (xmlChar *) value);
  660. if (!node) {
  661. RETURN_FALSE;
  662. }
  663. DOM_RET_OBJ(node, &ret, intern);
  664. }
  665. /* }}} end dom_document_create_comment */
  666. /* {{{ proto DOMCdataSection dom_document_create_cdatasection(string data)
  667. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-D26C0AF8
  668. Since:
  669. */
  670. PHP_FUNCTION(dom_document_create_cdatasection)
  671. {
  672. zval *id;
  673. xmlNode *node;
  674. xmlDocPtr docp;
  675. int ret;
  676. size_t value_len;
  677. dom_object *intern;
  678. char *value;
  679. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &id, dom_document_class_entry, &value, &value_len) == FAILURE) {
  680. return;
  681. }
  682. DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
  683. node = xmlNewCDataBlock(docp, (xmlChar *) value, value_len);
  684. if (!node) {
  685. RETURN_FALSE;
  686. }
  687. DOM_RET_OBJ(node, &ret, intern);
  688. }
  689. /* }}} end dom_document_create_cdatasection */
  690. /* {{{ proto DOMProcessingInstruction dom_document_create_processing_instruction(string target, string data)
  691. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-135944439
  692. Since:
  693. */
  694. PHP_FUNCTION(dom_document_create_processing_instruction)
  695. {
  696. zval *id;
  697. xmlNode *node;
  698. xmlDocPtr docp;
  699. int ret;
  700. size_t value_len, name_len = 0;
  701. dom_object *intern;
  702. char *name, *value = NULL;
  703. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os|s", &id, dom_document_class_entry, &name, &name_len, &value, &value_len) == FAILURE) {
  704. return;
  705. }
  706. DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
  707. if (xmlValidateName((xmlChar *) name, 0) != 0) {
  708. php_dom_throw_error(INVALID_CHARACTER_ERR, dom_get_strict_error(intern->document));
  709. RETURN_FALSE;
  710. }
  711. node = xmlNewPI((xmlChar *) name, (xmlChar *) value);
  712. if (!node) {
  713. RETURN_FALSE;
  714. }
  715. node->doc = docp;
  716. DOM_RET_OBJ(node, &ret, intern);
  717. }
  718. /* }}} end dom_document_create_processing_instruction */
  719. /* {{{ proto DOMAttr dom_document_create_attribute(string name)
  720. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1084891198
  721. Since:
  722. */
  723. PHP_FUNCTION(dom_document_create_attribute)
  724. {
  725. zval *id;
  726. xmlAttrPtr node;
  727. xmlDocPtr docp;
  728. int ret;
  729. size_t name_len;
  730. dom_object *intern;
  731. char *name;
  732. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &id, dom_document_class_entry, &name, &name_len) == FAILURE) {
  733. return;
  734. }
  735. DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
  736. if (xmlValidateName((xmlChar *) name, 0) != 0) {
  737. php_dom_throw_error(INVALID_CHARACTER_ERR, dom_get_strict_error(intern->document));
  738. RETURN_FALSE;
  739. }
  740. node = xmlNewDocProp(docp, (xmlChar *) name, NULL);
  741. if (!node) {
  742. RETURN_FALSE;
  743. }
  744. DOM_RET_OBJ((xmlNodePtr) node, &ret, intern);
  745. }
  746. /* }}} end dom_document_create_attribute */
  747. /* {{{ proto DOMEntityReference dom_document_create_entity_reference(string name)
  748. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-392B75AE
  749. Since:
  750. */
  751. PHP_FUNCTION(dom_document_create_entity_reference)
  752. {
  753. zval *id;
  754. xmlNode *node;
  755. xmlDocPtr docp = NULL;
  756. dom_object *intern;
  757. int ret;
  758. size_t name_len;
  759. char *name;
  760. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &id, dom_document_class_entry, &name, &name_len) == FAILURE) {
  761. return;
  762. }
  763. DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
  764. if (xmlValidateName((xmlChar *) name, 0) != 0) {
  765. php_dom_throw_error(INVALID_CHARACTER_ERR, dom_get_strict_error(intern->document));
  766. RETURN_FALSE;
  767. }
  768. node = xmlNewReference(docp, (xmlChar *) name);
  769. if (!node) {
  770. RETURN_FALSE;
  771. }
  772. DOM_RET_OBJ((xmlNodePtr) node, &ret, intern);
  773. }
  774. /* }}} end dom_document_create_entity_reference */
  775. /* {{{ proto DOMNodeList dom_document_get_elements_by_tag_name(string tagname)
  776. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-A6C9094
  777. Since:
  778. */
  779. PHP_FUNCTION(dom_document_get_elements_by_tag_name)
  780. {
  781. zval *id;
  782. xmlDocPtr docp;
  783. size_t name_len;
  784. dom_object *intern, *namednode;
  785. char *name;
  786. xmlChar *local;
  787. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &id, dom_document_class_entry, &name, &name_len) == FAILURE) {
  788. return;
  789. }
  790. DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
  791. php_dom_create_interator(return_value, DOM_NODELIST);
  792. namednode = Z_DOMOBJ_P(return_value);
  793. local = xmlCharStrndup(name, name_len);
  794. dom_namednode_iter(intern, 0, namednode, NULL, local, NULL);
  795. }
  796. /* }}} end dom_document_get_elements_by_tag_name */
  797. /* {{{ proto DOMNode dom_document_import_node(DOMNode importedNode, bool deep)
  798. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Core-Document-importNode
  799. Since: DOM Level 2
  800. */
  801. PHP_FUNCTION(dom_document_import_node)
  802. {
  803. zval *id, *node;
  804. xmlDocPtr docp;
  805. xmlNodePtr nodep, retnodep;
  806. dom_object *intern, *nodeobj;
  807. int ret;
  808. zend_bool recursive = 0;
  809. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "OO|b", &id, dom_document_class_entry, &node, dom_node_class_entry, &recursive) == FAILURE) {
  810. return;
  811. }
  812. DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
  813. DOM_GET_OBJ(nodep, node, xmlNodePtr, nodeobj);
  814. if (nodep->type == XML_HTML_DOCUMENT_NODE || nodep->type == XML_DOCUMENT_NODE
  815. || nodep->type == XML_DOCUMENT_TYPE_NODE) {
  816. php_error_docref(NULL, E_WARNING, "Cannot import: Node Type Not Supported");
  817. RETURN_FALSE;
  818. }
  819. if (nodep->doc == docp) {
  820. retnodep = nodep;
  821. } else {
  822. if ((recursive == 0) && (nodep->type == XML_ELEMENT_NODE)) {
  823. recursive = 2;
  824. }
  825. retnodep = xmlDocCopyNode(nodep, docp, recursive);
  826. if (!retnodep) {
  827. RETURN_FALSE;
  828. }
  829. if ((retnodep->type == XML_ATTRIBUTE_NODE) && (nodep->ns != NULL)) {
  830. xmlNsPtr nsptr = NULL;
  831. xmlNodePtr root = xmlDocGetRootElement(docp);
  832. nsptr = xmlSearchNsByHref (nodep->doc, root, nodep->ns->href);
  833. if (nsptr == NULL) {
  834. int errorcode;
  835. nsptr = dom_get_ns(root, (char *) nodep->ns->href, &errorcode, (char *) nodep->ns->prefix);
  836. }
  837. xmlSetNs(retnodep, nsptr);
  838. }
  839. }
  840. DOM_RET_OBJ((xmlNodePtr) retnodep, &ret, intern);
  841. }
  842. /* }}} end dom_document_import_node */
  843. /* {{{ proto DOMElement dom_document_create_element_ns(string namespaceURI, string qualifiedName [,string value])
  844. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-DocCrElNS
  845. Since: DOM Level 2
  846. */
  847. PHP_FUNCTION(dom_document_create_element_ns)
  848. {
  849. zval *id;
  850. xmlDocPtr docp;
  851. xmlNodePtr nodep = NULL;
  852. xmlNsPtr nsptr = NULL;
  853. int ret;
  854. size_t uri_len = 0, name_len = 0, value_len = 0;
  855. char *uri, *name, *value = NULL;
  856. char *localname = NULL, *prefix = NULL;
  857. int errorcode;
  858. dom_object *intern;
  859. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os!s|s", &id, dom_document_class_entry, &uri, &uri_len, &name, &name_len, &value, &value_len) == FAILURE) {
  860. return;
  861. }
  862. DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
  863. errorcode = dom_check_qname(name, &localname, &prefix, uri_len, name_len);
  864. if (errorcode == 0) {
  865. if (xmlValidateName((xmlChar *) localname, 0) == 0) {
  866. nodep = xmlNewDocNode(docp, NULL, (xmlChar *) localname, (xmlChar *) value);
  867. if (nodep != NULL && uri != NULL) {
  868. nsptr = xmlSearchNsByHref(nodep->doc, nodep, (xmlChar *) uri);
  869. if (nsptr == NULL) {
  870. nsptr = dom_get_ns(nodep, uri, &errorcode, prefix);
  871. }
  872. xmlSetNs(nodep, nsptr);
  873. }
  874. } else {
  875. errorcode = INVALID_CHARACTER_ERR;
  876. }
  877. }
  878. xmlFree(localname);
  879. if (prefix != NULL) {
  880. xmlFree(prefix);
  881. }
  882. if (errorcode != 0) {
  883. if (nodep != NULL) {
  884. xmlFreeNode(nodep);
  885. }
  886. php_dom_throw_error(errorcode, dom_get_strict_error(intern->document));
  887. RETURN_FALSE;
  888. }
  889. if (nodep == NULL) {
  890. RETURN_FALSE;
  891. }
  892. nodep->ns = nsptr;
  893. DOM_RET_OBJ(nodep, &ret, intern);
  894. }
  895. /* }}} end dom_document_create_element_ns */
  896. /* {{{ proto DOMAttr dom_document_create_attribute_ns(string namespaceURI, string qualifiedName)
  897. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-DocCrAttrNS
  898. Since: DOM Level 2
  899. */
  900. PHP_FUNCTION(dom_document_create_attribute_ns)
  901. {
  902. zval *id;
  903. xmlDocPtr docp;
  904. xmlNodePtr nodep = NULL, root;
  905. xmlNsPtr nsptr;
  906. int ret;
  907. size_t uri_len = 0, name_len = 0;
  908. char *uri, *name;
  909. char *localname = NULL, *prefix = NULL;
  910. dom_object *intern;
  911. int errorcode;
  912. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os!s", &id, dom_document_class_entry, &uri, &uri_len, &name, &name_len) == FAILURE) {
  913. return;
  914. }
  915. DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
  916. root = xmlDocGetRootElement(docp);
  917. if (root != NULL) {
  918. errorcode = dom_check_qname(name, &localname, &prefix, uri_len, name_len);
  919. if (errorcode == 0) {
  920. if (xmlValidateName((xmlChar *) localname, 0) == 0) {
  921. nodep = (xmlNodePtr) xmlNewDocProp(docp, (xmlChar *) localname, NULL);
  922. if (nodep != NULL && uri_len > 0) {
  923. nsptr = xmlSearchNsByHref(nodep->doc, root, (xmlChar *) uri);
  924. if (nsptr == NULL) {
  925. nsptr = dom_get_ns(root, uri, &errorcode, prefix);
  926. }
  927. xmlSetNs(nodep, nsptr);
  928. }
  929. } else {
  930. errorcode = INVALID_CHARACTER_ERR;
  931. }
  932. }
  933. } else {
  934. php_error_docref(NULL, E_WARNING, "Document Missing Root Element");
  935. RETURN_FALSE;
  936. }
  937. xmlFree(localname);
  938. if (prefix != NULL) {
  939. xmlFree(prefix);
  940. }
  941. if (errorcode != 0) {
  942. if (nodep != NULL) {
  943. xmlFreeProp((xmlAttrPtr) nodep);
  944. }
  945. php_dom_throw_error(errorcode, dom_get_strict_error(intern->document));
  946. RETURN_FALSE;
  947. }
  948. if (nodep == NULL) {
  949. RETURN_FALSE;
  950. }
  951. DOM_RET_OBJ(nodep, &ret, intern);
  952. }
  953. /* }}} end dom_document_create_attribute_ns */
  954. /* {{{ proto DOMNodeList dom_document_get_elements_by_tag_name_ns(string namespaceURI, string localName)
  955. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-getElBTNNS
  956. Since: DOM Level 2
  957. */
  958. PHP_FUNCTION(dom_document_get_elements_by_tag_name_ns)
  959. {
  960. zval *id;
  961. xmlDocPtr docp;
  962. size_t uri_len, name_len;
  963. dom_object *intern, *namednode;
  964. char *uri, *name;
  965. xmlChar *local, *nsuri;
  966. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Oss", &id, dom_document_class_entry, &uri, &uri_len, &name, &name_len) == FAILURE) {
  967. return;
  968. }
  969. DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
  970. php_dom_create_interator(return_value, DOM_NODELIST);
  971. namednode = Z_DOMOBJ_P(return_value);
  972. local = xmlCharStrndup(name, name_len);
  973. nsuri = xmlCharStrndup(uri, uri_len);
  974. dom_namednode_iter(intern, 0, namednode, NULL, local, nsuri);
  975. }
  976. /* }}} end dom_document_get_elements_by_tag_name_ns */
  977. /* {{{ proto DOMElement dom_document_get_element_by_id(string elementId)
  978. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-getElBId
  979. Since: DOM Level 2
  980. */
  981. PHP_FUNCTION(dom_document_get_element_by_id)
  982. {
  983. zval *id;
  984. xmlDocPtr docp;
  985. xmlAttrPtr attrp;
  986. int ret;
  987. size_t idname_len;
  988. dom_object *intern;
  989. char *idname;
  990. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &id, dom_document_class_entry, &idname, &idname_len) == FAILURE) {
  991. return;
  992. }
  993. DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
  994. attrp = xmlGetID(docp, (xmlChar *) idname);
  995. if (attrp && attrp->parent) {
  996. DOM_RET_OBJ((xmlNodePtr) attrp->parent, &ret, intern);
  997. } else {
  998. RETVAL_NULL();
  999. }
  1000. }
  1001. /* }}} end dom_document_get_element_by_id */
  1002. /* {{{ proto DOMNode dom_document_adopt_node(DOMNode source)
  1003. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-adoptNode
  1004. Since: DOM Level 3
  1005. */
  1006. PHP_FUNCTION(dom_document_adopt_node)
  1007. {
  1008. DOM_NOT_IMPLEMENTED();
  1009. }
  1010. /* }}} end dom_document_adopt_node */
  1011. /* {{{ proto void dom_document_normalize_document()
  1012. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-normalizeDocument
  1013. Since: DOM Level 3
  1014. */
  1015. PHP_FUNCTION(dom_document_normalize_document)
  1016. {
  1017. zval *id;
  1018. xmlDocPtr docp;
  1019. dom_object *intern;
  1020. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &id, dom_document_class_entry) == FAILURE) {
  1021. return;
  1022. }
  1023. DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
  1024. dom_normalize((xmlNodePtr) docp);
  1025. }
  1026. /* }}} end dom_document_normalize_document */
  1027. /* {{{ proto DOMNode dom_document_rename_node(node n, string namespaceURI, string qualifiedName)
  1028. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-renameNode
  1029. Since: DOM Level 3
  1030. */
  1031. PHP_FUNCTION(dom_document_rename_node)
  1032. {
  1033. DOM_NOT_IMPLEMENTED();
  1034. }
  1035. /* }}} end dom_document_rename_node */
  1036. /* {{{ proto DOMDocument::__construct([string version], [string encoding]); */
  1037. PHP_METHOD(domdocument, __construct)
  1038. {
  1039. zval *id = getThis();
  1040. xmlDoc *docp = NULL, *olddoc;
  1041. dom_object *intern;
  1042. char *encoding, *version = NULL;
  1043. size_t encoding_len = 0, version_len = 0;
  1044. int refcount;
  1045. if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|ss", &version, &version_len, &encoding, &encoding_len) == FAILURE) {
  1046. return;
  1047. }
  1048. docp = xmlNewDoc((xmlChar *) version);
  1049. if (!docp) {
  1050. php_dom_throw_error(INVALID_STATE_ERR, 1);
  1051. RETURN_FALSE;
  1052. }
  1053. if (encoding_len > 0) {
  1054. docp->encoding = (const xmlChar *) xmlStrdup((xmlChar *) encoding);
  1055. }
  1056. intern = Z_DOMOBJ_P(id);
  1057. if (intern != NULL) {
  1058. olddoc = (xmlDocPtr) dom_object_get_node(intern);
  1059. if (olddoc != NULL) {
  1060. php_libxml_decrement_node_ptr((php_libxml_node_object *) intern);
  1061. refcount = php_libxml_decrement_doc_ref((php_libxml_node_object *)intern);
  1062. if (refcount != 0) {
  1063. olddoc->_private = NULL;
  1064. }
  1065. }
  1066. intern->document = NULL;
  1067. if (php_libxml_increment_doc_ref((php_libxml_node_object *)intern, docp) == -1) {
  1068. RETURN_FALSE;
  1069. }
  1070. php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)docp, (void *)intern);
  1071. }
  1072. }
  1073. /* }}} end DOMDocument::__construct */
  1074. char *_dom_get_valid_file_path(char *source, char *resolved_path, int resolved_path_len ) /* {{{ */
  1075. {
  1076. xmlURI *uri;
  1077. xmlChar *escsource;
  1078. char *file_dest;
  1079. int isFileUri = 0;
  1080. uri = xmlCreateURI();
  1081. escsource = xmlURIEscapeStr((xmlChar *) source, (xmlChar *) ":");
  1082. xmlParseURIReference(uri, (char *) escsource);
  1083. xmlFree(escsource);
  1084. if (uri->scheme != NULL) {
  1085. /* absolute file uris - libxml only supports localhost or empty host */
  1086. #ifdef PHP_WIN32
  1087. if (strncasecmp(source, "file://",7) == 0 && ':' == source[8]) {
  1088. isFileUri = 1;
  1089. source += 7;
  1090. } else
  1091. #endif
  1092. if (strncasecmp(source, "file:///",8) == 0) {
  1093. isFileUri = 1;
  1094. #ifdef PHP_WIN32
  1095. source += 8;
  1096. #else
  1097. source += 7;
  1098. #endif
  1099. } else if (strncasecmp(source, "file://localhost/",17) == 0) {
  1100. isFileUri = 1;
  1101. #ifdef PHP_WIN32
  1102. source += 17;
  1103. #else
  1104. source += 16;
  1105. #endif
  1106. }
  1107. }
  1108. file_dest = source;
  1109. if ((uri->scheme == NULL || isFileUri)) {
  1110. /* XXX possible buffer overflow if VCWD_REALPATH does not know size of resolved_path */
  1111. if (!VCWD_REALPATH(source, resolved_path) && !expand_filepath(source, resolved_path)) {
  1112. xmlFreeURI(uri);
  1113. return NULL;
  1114. }
  1115. file_dest = resolved_path;
  1116. }
  1117. xmlFreeURI(uri);
  1118. return file_dest;
  1119. }
  1120. /* }}} */
  1121. static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, size_t source_len, size_t options) /* {{{ */
  1122. {
  1123. xmlDocPtr ret;
  1124. xmlParserCtxtPtr ctxt = NULL;
  1125. dom_doc_propsptr doc_props;
  1126. dom_object *intern;
  1127. php_libxml_ref_obj *document = NULL;
  1128. int validate, recover, resolve_externals, keep_blanks, substitute_ent;
  1129. int resolved_path_len;
  1130. int old_error_reporting = 0;
  1131. char *directory=NULL, resolved_path[MAXPATHLEN];
  1132. if (id != NULL) {
  1133. intern = Z_DOMOBJ_P(id);
  1134. document = intern->document;
  1135. }
  1136. doc_props = dom_get_doc_props(document);
  1137. validate = doc_props->validateonparse;
  1138. resolve_externals = doc_props->resolveexternals;
  1139. keep_blanks = doc_props->preservewhitespace;
  1140. substitute_ent = doc_props->substituteentities;
  1141. recover = doc_props->recover;
  1142. if (document == NULL) {
  1143. efree(doc_props);
  1144. }
  1145. xmlInitParser();
  1146. if (mode == DOM_LOAD_FILE) {
  1147. char *file_dest;
  1148. if (CHECK_NULL_PATH(source, source_len)) {
  1149. return NULL;
  1150. }
  1151. file_dest = _dom_get_valid_file_path(source, resolved_path, MAXPATHLEN);
  1152. if (file_dest) {
  1153. ctxt = xmlCreateFileParserCtxt(file_dest);
  1154. }
  1155. } else {
  1156. ctxt = xmlCreateMemoryParserCtxt(source, source_len);
  1157. }
  1158. if (ctxt == NULL) {
  1159. return(NULL);
  1160. }
  1161. /* If loading from memory, we need to set the base directory for the document */
  1162. if (mode != DOM_LOAD_FILE) {
  1163. #if HAVE_GETCWD
  1164. directory = VCWD_GETCWD(resolved_path, MAXPATHLEN);
  1165. #elif HAVE_GETWD
  1166. directory = VCWD_GETWD(resolved_path);
  1167. #endif
  1168. if (directory) {
  1169. if(ctxt->directory != NULL) {
  1170. xmlFree((char *) ctxt->directory);
  1171. }
  1172. resolved_path_len = strlen(resolved_path);
  1173. if (resolved_path[resolved_path_len - 1] != DEFAULT_SLASH) {
  1174. resolved_path[resolved_path_len] = DEFAULT_SLASH;
  1175. resolved_path[++resolved_path_len] = '\0';
  1176. }
  1177. ctxt->directory = (char *) xmlCanonicPath((const xmlChar *) resolved_path);
  1178. }
  1179. }
  1180. ctxt->vctxt.error = php_libxml_ctx_error;
  1181. ctxt->vctxt.warning = php_libxml_ctx_warning;
  1182. if (ctxt->sax != NULL) {
  1183. ctxt->sax->error = php_libxml_ctx_error;
  1184. ctxt->sax->warning = php_libxml_ctx_warning;
  1185. }
  1186. if (validate && ! (options & XML_PARSE_DTDVALID)) {
  1187. options |= XML_PARSE_DTDVALID;
  1188. }
  1189. if (resolve_externals && ! (options & XML_PARSE_DTDATTR)) {
  1190. options |= XML_PARSE_DTDATTR;
  1191. }
  1192. if (substitute_ent && ! (options & XML_PARSE_NOENT)) {
  1193. options |= XML_PARSE_NOENT;
  1194. }
  1195. if (keep_blanks == 0 && ! (options & XML_PARSE_NOBLANKS)) {
  1196. options |= XML_PARSE_NOBLANKS;
  1197. }
  1198. xmlCtxtUseOptions(ctxt, options);
  1199. ctxt->recovery = recover;
  1200. if (recover) {
  1201. old_error_reporting = EG(error_reporting);
  1202. EG(error_reporting) = old_error_reporting | E_WARNING;
  1203. }
  1204. xmlParseDocument(ctxt);
  1205. if (ctxt->wellFormed || recover) {
  1206. ret = ctxt->myDoc;
  1207. if (ctxt->recovery) {
  1208. EG(error_reporting) = old_error_reporting;
  1209. }
  1210. /* If loading from memory, set the base reference uri for the document */
  1211. if (ret && ret->URL == NULL && ctxt->directory != NULL) {
  1212. ret->URL = xmlStrdup((xmlChar *) ctxt->directory);
  1213. }
  1214. } else {
  1215. ret = NULL;
  1216. xmlFreeDoc(ctxt->myDoc);
  1217. ctxt->myDoc = NULL;
  1218. }
  1219. xmlFreeParserCtxt(ctxt);
  1220. return(ret);
  1221. }
  1222. /* }}} */
  1223. /* {{{ static void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode) */
  1224. static void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode) {
  1225. zval *id;
  1226. xmlDoc *docp = NULL, *newdoc;
  1227. dom_doc_propsptr doc_prop;
  1228. dom_object *intern;
  1229. char *source;
  1230. size_t source_len;
  1231. int refcount, ret;
  1232. zend_long options = 0;
  1233. id = getThis();
  1234. if (id != NULL && ! instanceof_function(Z_OBJCE_P(id), dom_document_class_entry)) {
  1235. id = NULL;
  1236. }
  1237. if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &source, &source_len, &options) == FAILURE) {
  1238. return;
  1239. }
  1240. if (!source_len) {
  1241. php_error_docref(NULL, E_WARNING, "Empty string supplied as input");
  1242. RETURN_FALSE;
  1243. }
  1244. if (ZEND_SIZE_T_INT_OVFL(source_len)) {
  1245. php_error_docref(NULL, E_WARNING, "Input string is too long");
  1246. RETURN_FALSE;
  1247. }
  1248. if (ZEND_LONG_EXCEEDS_INT(options)) {
  1249. php_error_docref(NULL, E_WARNING, "Invalid options");
  1250. RETURN_FALSE;
  1251. }
  1252. newdoc = dom_document_parser(id, mode, source, source_len, options);
  1253. if (!newdoc)
  1254. RETURN_FALSE;
  1255. if (id != NULL) {
  1256. intern = Z_DOMOBJ_P(id);
  1257. if (intern != NULL) {
  1258. docp = (xmlDocPtr) dom_object_get_node(intern);
  1259. doc_prop = NULL;
  1260. if (docp != NULL) {
  1261. php_libxml_decrement_node_ptr((php_libxml_node_object *) intern);
  1262. doc_prop = intern->document->doc_props;
  1263. intern->document->doc_props = NULL;
  1264. refcount = php_libxml_decrement_doc_ref((php_libxml_node_object *)intern);
  1265. if (refcount != 0) {
  1266. docp->_private = NULL;
  1267. }
  1268. }
  1269. intern->document = NULL;
  1270. if (php_libxml_increment_doc_ref((php_libxml_node_object *)intern, newdoc) == -1) {
  1271. RETURN_FALSE;
  1272. }
  1273. intern->document->doc_props = doc_prop;
  1274. }
  1275. php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)newdoc, (void *)intern);
  1276. RETURN_TRUE;
  1277. } else {
  1278. DOM_RET_OBJ((xmlNodePtr) newdoc, &ret, NULL);
  1279. }
  1280. }
  1281. /* }}} end dom_parser_document */
  1282. /* {{{ proto DOMNode dom_document_load(string source [, int options])
  1283. URL: http://www.w3.org/TR/DOM-Level-3-LS/load-save.html#LS-DocumentLS-load
  1284. Since: DOM Level 3
  1285. */
  1286. PHP_METHOD(domdocument, load)
  1287. {
  1288. dom_parse_document(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_FILE);
  1289. }
  1290. /* }}} end dom_document_load */
  1291. /* {{{ proto DOMNode dom_document_loadxml(string source [, int options])
  1292. URL: http://www.w3.org/TR/DOM-Level-3-LS/load-save.html#LS-DocumentLS-loadXML
  1293. Since: DOM Level 3
  1294. */
  1295. PHP_METHOD(domdocument, loadXML)
  1296. {
  1297. dom_parse_document(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_STRING);
  1298. }
  1299. /* }}} end dom_document_loadxml */
  1300. /* {{{ proto int dom_document_save(string file)
  1301. Convenience method to save to file
  1302. */
  1303. PHP_FUNCTION(dom_document_save)
  1304. {
  1305. zval *id;
  1306. xmlDoc *docp;
  1307. size_t file_len = 0;
  1308. int bytes, format, saveempty = 0;
  1309. dom_object *intern;
  1310. dom_doc_propsptr doc_props;
  1311. char *file;
  1312. zend_long options = 0;
  1313. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Op|l", &id, dom_document_class_entry, &file, &file_len, &options) == FAILURE) {
  1314. return;
  1315. }
  1316. if (file_len == 0) {
  1317. php_error_docref(NULL, E_WARNING, "Invalid Filename");
  1318. RETURN_FALSE;
  1319. }
  1320. DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
  1321. /* encoding handled by property on doc */
  1322. doc_props = dom_get_doc_props(intern->document);
  1323. format = doc_props->formatoutput;
  1324. if (options & LIBXML_SAVE_NOEMPTYTAG) {
  1325. saveempty = xmlSaveNoEmptyTags;
  1326. xmlSaveNoEmptyTags = 1;
  1327. }
  1328. bytes = xmlSaveFormatFileEnc(file, docp, NULL, format);
  1329. if (options & LIBXML_SAVE_NOEMPTYTAG) {
  1330. xmlSaveNoEmptyTags = saveempty;
  1331. }
  1332. if (bytes == -1) {
  1333. RETURN_FALSE;
  1334. }
  1335. RETURN_LONG(bytes);
  1336. }
  1337. /* }}} end dom_document_save */
  1338. /* {{{ proto string dom_document_savexml([node n])
  1339. URL: http://www.w3.org/TR/DOM-Level-3-LS/load-save.html#LS-DocumentLS-saveXML
  1340. Since: DOM Level 3
  1341. */
  1342. PHP_FUNCTION(dom_document_savexml)
  1343. {
  1344. zval *id, *nodep = NULL;
  1345. xmlDoc *docp;
  1346. xmlNode *node;
  1347. xmlBufferPtr buf;
  1348. xmlChar *mem;
  1349. dom_object *intern, *nodeobj;
  1350. dom_doc_propsptr doc_props;
  1351. int size, format, saveempty = 0;
  1352. zend_long options = 0;
  1353. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|O!l", &id, dom_document_class_entry, &nodep, dom_node_class_entry, &options) == FAILURE) {
  1354. return;
  1355. }
  1356. DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
  1357. doc_props = dom_get_doc_props(intern->document);
  1358. format = doc_props->formatoutput;
  1359. if (nodep != NULL) {
  1360. /* Dump contents of Node */
  1361. DOM_GET_OBJ(node, nodep, xmlNodePtr, nodeobj);
  1362. if (node->doc != docp) {
  1363. php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(intern->document));
  1364. RETURN_FALSE;
  1365. }
  1366. buf = xmlBufferCreate();
  1367. if (!buf) {
  1368. php_error_docref(NULL, E_WARNING, "Could not fetch buffer");
  1369. RETURN_FALSE;
  1370. }
  1371. if (options & LIBXML_SAVE_NOEMPTYTAG) {
  1372. saveempty = xmlSaveNoEmptyTags;
  1373. xmlSaveNoEmptyTags = 1;
  1374. }
  1375. xmlNodeDump(buf, docp, node, 0, format);
  1376. if (options & LIBXML_SAVE_NOEMPTYTAG) {
  1377. xmlSaveNoEmptyTags = saveempty;
  1378. }
  1379. mem = (xmlChar*) xmlBufferContent(buf);
  1380. if (!mem) {
  1381. xmlBufferFree(buf);
  1382. RETURN_FALSE;
  1383. }
  1384. RETVAL_STRING((char *) mem);
  1385. xmlBufferFree(buf);
  1386. } else {
  1387. if (options & LIBXML_SAVE_NOEMPTYTAG) {
  1388. saveempty = xmlSaveNoEmptyTags;
  1389. xmlSaveNoEmptyTags = 1;
  1390. }
  1391. /* Encoding is handled from the encoding property set on the document */
  1392. xmlDocDumpFormatMemory(docp, &mem, &size, format);
  1393. if (options & LIBXML_SAVE_NOEMPTYTAG) {
  1394. xmlSaveNoEmptyTags = saveempty;
  1395. }
  1396. if (!size || !mem) {
  1397. RETURN_FALSE;
  1398. }
  1399. RETVAL_STRINGL((char *) mem, size);
  1400. xmlFree(mem);
  1401. }
  1402. }
  1403. /* }}} end dom_document_savexml */
  1404. static xmlNodePtr php_dom_free_xinclude_node(xmlNodePtr cur) /* {{{ */
  1405. {
  1406. xmlNodePtr xincnode;
  1407. xincnode = cur;
  1408. cur = cur->next;
  1409. xmlUnlinkNode(xincnode);
  1410. php_libxml_node_free_resource(xincnode);
  1411. return cur;
  1412. }
  1413. /* }}} */
  1414. static void php_dom_remove_xinclude_nodes(xmlNodePtr cur) /* {{{ */
  1415. {
  1416. while(cur) {
  1417. if (cur->type == XML_XINCLUDE_START) {
  1418. cur = php_dom_free_xinclude_node(cur);
  1419. /* XML_XINCLUDE_END node will be a sibling of XML_XINCLUDE_START */
  1420. while(cur && cur->type != XML_XINCLUDE_END) {
  1421. /* remove xinclude processing nodes from recursive xincludes */
  1422. if (cur->type == XML_ELEMENT_NODE) {
  1423. php_dom_remove_xinclude_nodes(cur->children);
  1424. }
  1425. cur = cur->next;
  1426. }
  1427. if (cur && cur->type == XML_XINCLUDE_END) {
  1428. cur = php_dom_free_xinclude_node(cur);
  1429. }
  1430. } else {
  1431. if (cur->type == XML_ELEMENT_NODE) {
  1432. php_dom_remove_xinclude_nodes(cur->children);
  1433. }
  1434. cur = cur->next;
  1435. }
  1436. }
  1437. }
  1438. /* }}} */
  1439. /* {{{ proto int dom_document_xinclude([int options])
  1440. Substitutues xincludes in a DomDocument */
  1441. PHP_FUNCTION(dom_document_xinclude)
  1442. {
  1443. zval *id;
  1444. xmlDoc *docp;
  1445. xmlNodePtr root;
  1446. zend_long flags = 0;
  1447. int err;
  1448. dom_object *intern;
  1449. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|l", &id, dom_document_class_entry, &flags) == FAILURE) {
  1450. return;
  1451. }
  1452. if (ZEND_LONG_EXCEEDS_INT(flags)) {
  1453. php_error_docref(NULL, E_WARNING, "Invalid flags");
  1454. RETURN_FALSE;
  1455. }
  1456. DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
  1457. err = xmlXIncludeProcessFlags(docp, (int)flags);
  1458. /* XML_XINCLUDE_START and XML_XINCLUDE_END nodes need to be removed as these
  1459. are added via xmlXIncludeProcess to mark beginning and ending of xincluded document
  1460. but are not wanted in resulting document - must be done even if err as it could fail after
  1461. having processed some xincludes */
  1462. root = (xmlNodePtr) docp->children;
  1463. while(root && root->type != XML_ELEMENT_NODE && root->type != XML_XINCLUDE_START) {
  1464. root = root->next;
  1465. }
  1466. if (root) {
  1467. php_dom_remove_xinclude_nodes(root);
  1468. }
  1469. if (err) {
  1470. RETVAL_LONG(err);
  1471. } else {
  1472. RETVAL_FALSE;
  1473. }
  1474. }
  1475. /* }}} */
  1476. /* {{{ proto bool dom_document_validate()
  1477. Since: DOM extended
  1478. */
  1479. PHP_FUNCTION(dom_document_validate)
  1480. {
  1481. zval *id;
  1482. xmlDoc *docp;
  1483. dom_object *intern;
  1484. xmlValidCtxt *cvp;
  1485. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &id, dom_document_class_entry) == FAILURE) {
  1486. return;
  1487. }
  1488. DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
  1489. cvp = xmlNewValidCtxt();
  1490. cvp->userData = NULL;
  1491. cvp->error = (xmlValidityErrorFunc) php_libxml_error_handler;
  1492. cvp->warning = (xmlValidityErrorFunc) php_libxml_error_handler;
  1493. if (xmlValidateDocument(cvp, docp)) {
  1494. RETVAL_TRUE;
  1495. } else {
  1496. RETVAL_FALSE;
  1497. }
  1498. xmlFreeValidCtxt(cvp);
  1499. }
  1500. /* }}} */
  1501. #if defined(LIBXML_SCHEMAS_ENABLED)
  1502. static void _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
  1503. {
  1504. zval *id;
  1505. xmlDoc *docp;
  1506. dom_object *intern;
  1507. char *source = NULL, *valid_file = NULL;
  1508. size_t source_len = 0;
  1509. int valid_opts = 0;
  1510. zend_long flags = 0;
  1511. xmlSchemaParserCtxtPtr parser;
  1512. xmlSchemaPtr sptr;
  1513. xmlSchemaValidCtxtPtr vptr;
  1514. int is_valid;
  1515. char resolved_path[MAXPATHLEN + 1];
  1516. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os|l", &id, dom_document_class_entry, &source, &source_len, &flags) == FAILURE) {
  1517. return;
  1518. }
  1519. if (source_len == 0) {
  1520. php_error_docref(NULL, E_WARNING, "Invalid Schema source");
  1521. RETURN_FALSE;
  1522. }
  1523. DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
  1524. switch (type) {
  1525. case DOM_LOAD_FILE:
  1526. if (CHECK_NULL_PATH(source, source_len)) {
  1527. php_error_docref(NULL, E_WARNING, "Invalid Schema file source");
  1528. RETURN_FALSE;
  1529. }
  1530. valid_file = _dom_get_valid_file_path(source, resolved_path, MAXPATHLEN);
  1531. if (!valid_file) {
  1532. php_error_docref(NULL, E_WARNING, "Invalid Schema file source");
  1533. RETURN_FALSE;
  1534. }
  1535. parser = xmlSchemaNewParserCtxt(valid_file);
  1536. break;
  1537. case DOM_LOAD_STRING:
  1538. parser = xmlSchemaNewMemParserCtxt(source, source_len);
  1539. /* If loading from memory, we need to set the base directory for the document
  1540. but it is not apparent how to do that for schema's */
  1541. break;
  1542. default:
  1543. return;
  1544. }
  1545. xmlSchemaSetParserErrors(parser,
  1546. (xmlSchemaValidityErrorFunc) php_libxml_error_handler,
  1547. (xmlSchemaValidityWarningFunc) php_libxml_error_handler,
  1548. parser);
  1549. sptr = xmlSchemaParse(parser);
  1550. xmlSchemaFreeParserCtxt(parser);
  1551. if (!sptr) {
  1552. php_error_docref(NULL, E_WARNING, "Invalid Schema");
  1553. RETURN_FALSE;
  1554. }
  1555. docp = (xmlDocPtr) dom_object_get_node(intern);
  1556. vptr = xmlSchemaNewValidCtxt(sptr);
  1557. if (!vptr) {
  1558. xmlSchemaFree(sptr);
  1559. zend_throw_error(NULL, "Invalid Schema Validation Context");
  1560. RETURN_FALSE;
  1561. }
  1562. #if LIBXML_VERSION >= 20614
  1563. if (flags & XML_SCHEMA_VAL_VC_I_CREATE) {
  1564. valid_opts |= XML_SCHEMA_VAL_VC_I_CREATE;
  1565. }
  1566. #endif
  1567. xmlSchemaSetValidOptions(vptr, valid_opts);
  1568. xmlSchemaSetValidErrors(vptr, php_libxml_error_handler, php_libxml_error_handler, vptr);
  1569. is_valid = xmlSchemaValidateDoc(vptr, docp);
  1570. xmlSchemaFree(sptr);
  1571. xmlSchemaFreeValidCtxt(vptr);
  1572. if (is_valid == 0) {
  1573. RETURN_TRUE;
  1574. } else {
  1575. RETURN_FALSE;
  1576. }
  1577. }
  1578. /* }}} */
  1579. /* {{{ proto bool dom_document_schema_validate_file(string filename, int flags); */
  1580. PHP_FUNCTION(dom_document_schema_validate_file)
  1581. {
  1582. _dom_document_schema_validate(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_FILE);
  1583. }
  1584. /* }}} end dom_document_schema_validate_file */
  1585. /* {{{ proto bool dom_document_schema_validate(string source, int flags); */
  1586. PHP_FUNCTION(dom_document_schema_validate_xml)
  1587. {
  1588. _dom_document_schema_validate(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_STRING);
  1589. }
  1590. /* }}} end dom_document_schema_validate */
  1591. static void _dom_document_relaxNG_validate(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
  1592. {
  1593. zval *id;
  1594. xmlDoc *docp;
  1595. dom_object *intern;
  1596. char *source = NULL, *valid_file = NULL;
  1597. size_t source_len = 0;
  1598. xmlRelaxNGParserCtxtPtr parser;
  1599. xmlRelaxNGPtr sptr;
  1600. xmlRelaxNGValidCtxtPtr vptr;
  1601. int is_valid;
  1602. char resolved_path[MAXPATHLEN + 1];
  1603. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &id, dom_document_class_entry, &source, &source_len) == FAILURE) {
  1604. return;
  1605. }
  1606. if (source_len == 0) {
  1607. php_error_docref(NULL, E_WARNING, "Invalid Schema source");
  1608. RETURN_FALSE;
  1609. }
  1610. DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
  1611. switch (type) {
  1612. case DOM_LOAD_FILE:
  1613. if (CHECK_NULL_PATH(source, source_len)) {
  1614. php_error_docref(NULL, E_WARNING, "Invalid RelaxNG file source");
  1615. RETURN_FALSE;
  1616. }
  1617. valid_file = _dom_get_valid_file_path(source, resolved_path, MAXPATHLEN);
  1618. if (!valid_file) {
  1619. php_error_docref(NULL, E_WARNING, "Invalid RelaxNG file source");
  1620. RETURN_FALSE;
  1621. }
  1622. parser = xmlRelaxNGNewParserCtxt(valid_file);
  1623. break;
  1624. case DOM_LOAD_STRING:
  1625. parser = xmlRelaxNGNewMemParserCtxt(source, source_len);
  1626. /* If loading from memory, we need to set the base directory for the document
  1627. but it is not apparent how to do that for schema's */
  1628. break;
  1629. default:
  1630. return;
  1631. }
  1632. xmlRelaxNGSetParserErrors(parser,
  1633. (xmlRelaxNGValidityErrorFunc) php_libxml_error_handler,
  1634. (xmlRelaxNGValidityWarningFunc) php_libxml_error_handler,
  1635. parser);
  1636. sptr = xmlRelaxNGParse(parser);
  1637. xmlRelaxNGFreeParserCtxt(parser);
  1638. if (!sptr) {
  1639. php_error_docref(NULL, E_WARNING, "Invalid RelaxNG");
  1640. RETURN_FALSE;
  1641. }
  1642. docp = (xmlDocPtr) dom_object_get_node(intern);
  1643. vptr = xmlRelaxNGNewValidCtxt(sptr);
  1644. if (!vptr) {
  1645. xmlRelaxNGFree(sptr);
  1646. zend_throw_error(NULL, "Invalid RelaxNG Validation Context");
  1647. RETURN_FALSE;
  1648. }
  1649. xmlRelaxNGSetValidErrors(vptr, php_libxml_error_handler, php_libxml_error_handler, vptr);
  1650. is_valid = xmlRelaxNGValidateDoc(vptr, docp);
  1651. xmlRelaxNGFree(sptr);
  1652. xmlRelaxNGFreeValidCtxt(vptr);
  1653. if (is_valid == 0) {
  1654. RETURN_TRUE;
  1655. } else {
  1656. RETURN_FALSE;
  1657. }
  1658. }
  1659. /* }}} */
  1660. /* {{{ proto bool dom_document_relaxNG_validate_file(string filename); */
  1661. PHP_FUNCTION(dom_document_relaxNG_validate_file)
  1662. {
  1663. _dom_document_relaxNG_validate(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_FILE);
  1664. }
  1665. /* }}} end dom_document_relaxNG_validate_file */
  1666. /* {{{ proto bool dom_document_relaxNG_validate_xml(string source); */
  1667. PHP_FUNCTION(dom_document_relaxNG_validate_xml)
  1668. {
  1669. _dom_document_relaxNG_validate(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_STRING);
  1670. }
  1671. /* }}} end dom_document_relaxNG_validate_xml */
  1672. #endif
  1673. #if defined(LIBXML_HTML_ENABLED)
  1674. static void dom_load_html(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */
  1675. {
  1676. zval *id;
  1677. xmlDoc *docp = NULL, *newdoc;
  1678. dom_object *intern;
  1679. dom_doc_propsptr doc_prop;
  1680. char *source;
  1681. size_t source_len;
  1682. int refcount, ret;
  1683. zend_long options = 0;
  1684. htmlParserCtxtPtr ctxt;
  1685. id = getThis();
  1686. if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &source, &source_len, &options) == FAILURE) {
  1687. return;
  1688. }
  1689. if (!source_len) {
  1690. php_error_docref(NULL, E_WARNING, "Empty string supplied as input");
  1691. RETURN_FALSE;
  1692. }
  1693. if (ZEND_LONG_EXCEEDS_INT(options)) {
  1694. php_error_docref(NULL, E_WARNING, "Invalid options");
  1695. RETURN_FALSE;
  1696. }
  1697. if (mode == DOM_LOAD_FILE) {
  1698. if (CHECK_NULL_PATH(source, source_len)) {
  1699. php_error_docref(NULL, E_WARNING, "Invalid file source");
  1700. RETURN_FALSE;
  1701. }
  1702. ctxt = htmlCreateFileParserCtxt(source, NULL);
  1703. } else {
  1704. if (ZEND_SIZE_T_INT_OVFL(source_len)) {
  1705. php_error_docref(NULL, E_WARNING, "Input string is too long");
  1706. RETURN_FALSE;
  1707. }
  1708. ctxt = htmlCreateMemoryParserCtxt(source, (int)source_len);
  1709. }
  1710. if (!ctxt) {
  1711. RETURN_FALSE;
  1712. }
  1713. ctxt->vctxt.error = php_libxml_ctx_error;
  1714. ctxt->vctxt.warning = php_libxml_ctx_warning;
  1715. if (ctxt->sax != NULL) {
  1716. ctxt->sax->error = php_libxml_ctx_error;
  1717. ctxt->sax->warning = php_libxml_ctx_warning;
  1718. }
  1719. if (options) {
  1720. htmlCtxtUseOptions(ctxt, (int)options);
  1721. }
  1722. htmlParseDocument(ctxt);
  1723. newdoc = ctxt->myDoc;
  1724. htmlFreeParserCtxt(ctxt);
  1725. if (!newdoc)
  1726. RETURN_FALSE;
  1727. if (id != NULL && instanceof_function(Z_OBJCE_P(id), dom_document_class_entry)) {
  1728. intern = Z_DOMOBJ_P(id);
  1729. if (intern != NULL) {
  1730. docp = (xmlDocPtr) dom_object_get_node(intern);
  1731. doc_prop = NULL;
  1732. if (docp != NULL) {
  1733. php_libxml_decrement_node_ptr((php_libxml_node_object *) intern);
  1734. doc_prop = intern->document->doc_props;
  1735. intern->document->doc_props = NULL;
  1736. refcount = php_libxml_decrement_doc_ref((php_libxml_node_object *)intern);
  1737. if (refcount != 0) {
  1738. docp->_private = NULL;
  1739. }
  1740. }
  1741. intern->document = NULL;
  1742. if (php_libxml_increment_doc_ref((php_libxml_node_object *)intern, newdoc) == -1) {
  1743. RETURN_FALSE;
  1744. }
  1745. intern->document->doc_props = doc_prop;
  1746. }
  1747. php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)newdoc, (void *)intern);
  1748. RETURN_TRUE;
  1749. } else {
  1750. DOM_RET_OBJ((xmlNodePtr) newdoc, &ret, NULL);
  1751. }
  1752. }
  1753. /* }}} */
  1754. /* {{{ proto DOMNode dom_document_load_html_file(string source)
  1755. Since: DOM extended
  1756. */
  1757. PHP_METHOD(domdocument, loadHTMLFile)
  1758. {
  1759. dom_load_html(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_FILE);
  1760. }
  1761. /* }}} end dom_document_load_html_file */
  1762. /* {{{ proto DOMNode dom_document_load_html(string source)
  1763. Since: DOM extended
  1764. */
  1765. PHP_METHOD(domdocument, loadHTML)
  1766. {
  1767. dom_load_html(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_STRING);
  1768. }
  1769. /* }}} end dom_document_load_html */
  1770. /* {{{ proto int dom_document_save_html_file(string file)
  1771. Convenience method to save to file as html
  1772. */
  1773. PHP_FUNCTION(dom_document_save_html_file)
  1774. {
  1775. zval *id;
  1776. xmlDoc *docp;
  1777. size_t file_len;
  1778. int bytes, format;
  1779. dom_object *intern;
  1780. dom_doc_propsptr doc_props;
  1781. char *file;
  1782. const char *encoding;
  1783. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Op", &id, dom_document_class_entry, &file, &file_len) == FAILURE) {
  1784. return;
  1785. }
  1786. if (file_len == 0) {
  1787. php_error_docref(NULL, E_WARNING, "Invalid Filename");
  1788. RETURN_FALSE;
  1789. }
  1790. DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
  1791. encoding = (const char *) htmlGetMetaEncoding(docp);
  1792. doc_props = dom_get_doc_props(intern->document);
  1793. format = doc_props->formatoutput;
  1794. bytes = htmlSaveFileFormat(file, docp, encoding, format);
  1795. if (bytes == -1) {
  1796. RETURN_FALSE;
  1797. }
  1798. RETURN_LONG(bytes);
  1799. }
  1800. /* }}} end dom_document_save_html_file */
  1801. /* {{{ proto string dom_document_save_html()
  1802. Convenience method to output as html
  1803. */
  1804. PHP_FUNCTION(dom_document_save_html)
  1805. {
  1806. zval *id, *nodep = NULL;
  1807. xmlDoc *docp;
  1808. xmlNode *node;
  1809. xmlOutputBufferPtr outBuf;
  1810. xmlBufferPtr buf;
  1811. dom_object *intern, *nodeobj;
  1812. xmlChar *mem = NULL;
  1813. int format;
  1814. dom_doc_propsptr doc_props;
  1815. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(),
  1816. "O|O!", &id, dom_document_class_entry, &nodep, dom_node_class_entry)
  1817. == FAILURE) {
  1818. return;
  1819. }
  1820. DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
  1821. doc_props = dom_get_doc_props(intern->document);
  1822. format = doc_props->formatoutput;
  1823. if (nodep != NULL) {
  1824. /* Dump contents of Node */
  1825. DOM_GET_OBJ(node, nodep, xmlNodePtr, nodeobj);
  1826. if (node->doc != docp) {
  1827. php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(intern->document));
  1828. RETURN_FALSE;
  1829. }
  1830. buf = xmlBufferCreate();
  1831. if (!buf) {
  1832. php_error_docref(NULL, E_WARNING, "Could not fetch buffer");
  1833. RETURN_FALSE;
  1834. }
  1835. outBuf = xmlOutputBufferCreateBuffer(buf, NULL);
  1836. if (!outBuf) {
  1837. xmlBufferFree(buf);
  1838. php_error_docref(NULL, E_WARNING, "Could not fetch output buffer");
  1839. RETURN_FALSE;
  1840. }
  1841. if (node->type == XML_DOCUMENT_FRAG_NODE) {
  1842. for (node = node->children; node; node = node->next) {
  1843. htmlNodeDumpFormatOutput(outBuf, docp, node, NULL, format);
  1844. if (outBuf->error) {
  1845. break;
  1846. }
  1847. }
  1848. } else {
  1849. htmlNodeDumpFormatOutput(outBuf, docp, node, NULL, format);
  1850. }
  1851. if (!outBuf->error) {
  1852. xmlOutputBufferFlush(outBuf);
  1853. mem = (xmlChar*) xmlBufferContent(buf);
  1854. if (!mem) {
  1855. RETVAL_FALSE;
  1856. } else {
  1857. int size = xmlBufferLength(buf);
  1858. RETVAL_STRINGL((const char*) mem, size);
  1859. }
  1860. } else {
  1861. php_error_docref(NULL, E_WARNING, "Error dumping HTML node");
  1862. RETVAL_FALSE;
  1863. }
  1864. xmlOutputBufferClose(outBuf);
  1865. xmlBufferFree(buf);
  1866. } else {
  1867. int size = 0;
  1868. #if LIBXML_VERSION >= 20623
  1869. htmlDocDumpMemoryFormat(docp, &mem, &size, format);
  1870. #else
  1871. htmlDocDumpMemory(docp, &mem, &size);
  1872. #endif
  1873. if (!size || !mem) {
  1874. RETVAL_FALSE;
  1875. } else {
  1876. RETVAL_STRINGL((const char*) mem, size);
  1877. }
  1878. if (mem)
  1879. xmlFree(mem);
  1880. }
  1881. }
  1882. /* }}} end dom_document_save_html */
  1883. #endif /* defined(LIBXML_HTML_ENABLED) */
  1884. /* {{{ proto bool DOMDocument::registerNodeClass(string baseclass, string extendedclass)
  1885. Register extended class used to create base node type */
  1886. PHP_METHOD(domdocument, registerNodeClass)
  1887. {
  1888. zval *id;
  1889. xmlDoc *docp;
  1890. zend_class_entry *basece = dom_node_class_entry, *ce = NULL;
  1891. dom_object *intern;
  1892. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "OCC!", &id, dom_document_class_entry, &basece, &ce) == FAILURE) {
  1893. return;
  1894. }
  1895. if (ce == NULL || instanceof_function(ce, basece)) {
  1896. DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
  1897. dom_set_doc_classmap(intern->document, basece, ce);
  1898. RETURN_TRUE;
  1899. }
  1900. zend_throw_error(NULL, "Class %s is not derived from %s.", ZSTR_VAL(ce->name), ZSTR_VAL(basece->name));
  1901. RETURN_FALSE;
  1902. }
  1903. /* }}} */
  1904. #endif /* HAVE_LIBXML && HAVE_DOM */
  1905. /*
  1906. * Local variables:
  1907. * tab-width: 4
  1908. * c-basic-offset: 4
  1909. * End:
  1910. * vim600: noet sw=4 ts=4 fdm=marker
  1911. * vim<600: noet sw=4 ts=4
  1912. */