element.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | https://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Authors: Christian Stocker <chregu@php.net> |
  14. | Rob Richards <rrichards@php.net> |
  15. +----------------------------------------------------------------------+
  16. */
  17. #ifdef HAVE_CONFIG_H
  18. #include "config.h"
  19. #endif
  20. #include "php.h"
  21. #if defined(HAVE_LIBXML) && defined(HAVE_DOM)
  22. #include "php_dom.h"
  23. /*
  24. * class DOMElement extends DOMNode
  25. *
  26. * URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-745549614
  27. * Since:
  28. */
  29. /* {{{ */
  30. PHP_METHOD(DOMElement, __construct)
  31. {
  32. xmlNodePtr nodep = NULL, oldnode = NULL;
  33. dom_object *intern;
  34. char *name, *value = NULL, *uri = NULL;
  35. char *localname = NULL, *prefix = NULL;
  36. int errorcode = 0;
  37. size_t name_len, value_len = 0, uri_len = 0;
  38. int name_valid;
  39. xmlNsPtr nsptr = NULL;
  40. if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!s", &name, &name_len, &value, &value_len, &uri, &uri_len) == FAILURE) {
  41. RETURN_THROWS();
  42. }
  43. name_valid = xmlValidateName((xmlChar *) name, 0);
  44. if (name_valid != 0) {
  45. php_dom_throw_error(INVALID_CHARACTER_ERR, 1);
  46. RETURN_THROWS();
  47. }
  48. /* Namespace logic is separate and only when uri passed in to insure no BC breakage */
  49. if (uri_len > 0) {
  50. errorcode = dom_check_qname(name, &localname, &prefix, uri_len, name_len);
  51. if (errorcode == 0) {
  52. nodep = xmlNewNode (NULL, (xmlChar *)localname);
  53. if (nodep != NULL && uri != NULL) {
  54. nsptr = dom_get_ns(nodep, uri, &errorcode, prefix);
  55. xmlSetNs(nodep, nsptr);
  56. }
  57. }
  58. xmlFree(localname);
  59. if (prefix != NULL) {
  60. xmlFree(prefix);
  61. }
  62. if (errorcode != 0) {
  63. if (nodep != NULL) {
  64. xmlFreeNode(nodep);
  65. }
  66. php_dom_throw_error(errorcode, 1);
  67. RETURN_THROWS();
  68. }
  69. } else {
  70. /* If you don't pass a namespace uri, then you can't set a prefix */
  71. localname = (char *) xmlSplitQName2((xmlChar *) name, (xmlChar **) &prefix);
  72. if (prefix != NULL) {
  73. xmlFree(localname);
  74. xmlFree(prefix);
  75. php_dom_throw_error(NAMESPACE_ERR, 1);
  76. RETURN_THROWS();
  77. }
  78. nodep = xmlNewNode(NULL, (xmlChar *) name);
  79. }
  80. if (!nodep) {
  81. php_dom_throw_error(INVALID_STATE_ERR, 1);
  82. RETURN_THROWS();
  83. }
  84. if (value_len > 0) {
  85. xmlNodeSetContentLen(nodep, (xmlChar *) value, value_len);
  86. }
  87. intern = Z_DOMOBJ_P(ZEND_THIS);
  88. oldnode = dom_object_get_node(intern);
  89. if (oldnode != NULL) {
  90. php_libxml_node_free_resource(oldnode );
  91. }
  92. php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern);
  93. }
  94. /* }}} end DOMElement::__construct */
  95. /* {{{ tagName string
  96. readonly=yes
  97. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-104682815
  98. Since:
  99. */
  100. int dom_element_tag_name_read(dom_object *obj, zval *retval)
  101. {
  102. xmlNodePtr nodep;
  103. xmlNsPtr ns;
  104. xmlChar *qname;
  105. nodep = dom_object_get_node(obj);
  106. if (nodep == NULL) {
  107. php_dom_throw_error(INVALID_STATE_ERR, 1);
  108. return FAILURE;
  109. }
  110. ns = nodep->ns;
  111. if (ns != NULL && ns->prefix) {
  112. qname = xmlStrdup(ns->prefix);
  113. qname = xmlStrcat(qname, (xmlChar *)":");
  114. qname = xmlStrcat(qname, nodep->name);
  115. ZVAL_STRING(retval, (char *)qname);
  116. xmlFree(qname);
  117. } else {
  118. ZVAL_STRING(retval, (char *) nodep->name);
  119. }
  120. return SUCCESS;
  121. }
  122. /* }}} */
  123. /* {{{ schemaTypeInfo typeinfo
  124. readonly=yes
  125. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Element-schemaTypeInfo
  126. Since: DOM Level 3
  127. */
  128. int dom_element_schema_type_info_read(dom_object *obj, zval *retval)
  129. {
  130. ZVAL_NULL(retval);
  131. return SUCCESS;
  132. }
  133. /* }}} */
  134. static xmlNodePtr dom_get_dom1_attribute(xmlNodePtr elem, xmlChar *name) /* {{{ */
  135. {
  136. int len;
  137. const xmlChar *nqname;
  138. nqname = xmlSplitQName3(name, &len);
  139. if (nqname != NULL) {
  140. xmlNsPtr ns;
  141. xmlChar *prefix = xmlStrndup(name, len);
  142. if (prefix && xmlStrEqual(prefix, (xmlChar *)"xmlns")) {
  143. ns = elem->nsDef;
  144. while (ns) {
  145. if (xmlStrEqual(ns->prefix, nqname)) {
  146. break;
  147. }
  148. ns = ns->next;
  149. }
  150. xmlFree(prefix);
  151. return (xmlNodePtr)ns;
  152. }
  153. ns = xmlSearchNs(elem->doc, elem, prefix);
  154. if (prefix != NULL) {
  155. xmlFree(prefix);
  156. }
  157. if (ns != NULL) {
  158. return (xmlNodePtr)xmlHasNsProp(elem, nqname, ns->href);
  159. }
  160. } else {
  161. if (xmlStrEqual(name, (xmlChar *)"xmlns")) {
  162. xmlNsPtr nsPtr = elem->nsDef;
  163. while (nsPtr) {
  164. if (nsPtr->prefix == NULL) {
  165. return (xmlNodePtr)nsPtr;
  166. }
  167. nsPtr = nsPtr->next;
  168. }
  169. return NULL;
  170. }
  171. }
  172. return (xmlNodePtr)xmlHasNsProp(elem, name, NULL);
  173. }
  174. /* }}} */
  175. /* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-666EE0F9
  176. Since:
  177. */
  178. PHP_METHOD(DOMElement, getAttribute)
  179. {
  180. zval *id;
  181. xmlNode *nodep;
  182. char *name;
  183. xmlChar *value = NULL;
  184. dom_object *intern;
  185. xmlNodePtr attr;
  186. size_t name_len;
  187. id = ZEND_THIS;
  188. if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
  189. RETURN_THROWS();
  190. }
  191. DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
  192. attr = dom_get_dom1_attribute(nodep, (xmlChar *)name);
  193. if (attr) {
  194. switch (attr->type) {
  195. case XML_ATTRIBUTE_NODE:
  196. value = xmlNodeListGetString(attr->doc, attr->children, 1);
  197. break;
  198. case XML_NAMESPACE_DECL:
  199. value = xmlStrdup(((xmlNsPtr)attr)->href);
  200. break;
  201. default:
  202. value = xmlStrdup(((xmlAttributePtr)attr)->defaultValue);
  203. }
  204. }
  205. if (value == NULL) {
  206. RETURN_EMPTY_STRING();
  207. } else {
  208. RETVAL_STRING((char *)value);
  209. xmlFree(value);
  210. }
  211. }
  212. /* }}} end dom_element_get_attribute */
  213. /* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-F68F082
  214. Since:
  215. */
  216. PHP_METHOD(DOMElement, setAttribute)
  217. {
  218. zval *id;
  219. xmlNode *nodep;
  220. xmlNodePtr attr = NULL;
  221. int ret, name_valid;
  222. size_t name_len, value_len;
  223. dom_object *intern;
  224. char *name, *value;
  225. id = ZEND_THIS;
  226. if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &name_len, &value, &value_len) == FAILURE) {
  227. RETURN_THROWS();
  228. }
  229. if (name_len == 0) {
  230. zend_argument_value_error(1, "cannot be empty");
  231. RETURN_THROWS();
  232. }
  233. name_valid = xmlValidateName((xmlChar *) name, 0);
  234. if (name_valid != 0) {
  235. php_dom_throw_error(INVALID_CHARACTER_ERR, 1);
  236. RETURN_THROWS();
  237. }
  238. DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
  239. if (dom_node_is_read_only(nodep) == SUCCESS) {
  240. php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document));
  241. RETURN_FALSE;
  242. }
  243. attr = dom_get_dom1_attribute(nodep, (xmlChar *)name);
  244. if (attr != NULL) {
  245. switch (attr->type) {
  246. case XML_ATTRIBUTE_NODE:
  247. node_list_unlink(attr->children);
  248. break;
  249. case XML_NAMESPACE_DECL:
  250. RETURN_FALSE;
  251. default:
  252. break;
  253. }
  254. }
  255. if (xmlStrEqual((xmlChar *)name, (xmlChar *)"xmlns")) {
  256. if (xmlNewNs(nodep, (xmlChar *)value, NULL)) {
  257. RETURN_TRUE;
  258. }
  259. } else {
  260. attr = (xmlNodePtr)xmlSetProp(nodep, (xmlChar *) name, (xmlChar *)value);
  261. }
  262. if (!attr) {
  263. zend_argument_value_error(1, "must be a valid XML attribute");
  264. RETURN_THROWS();
  265. }
  266. DOM_RET_OBJ(attr, &ret, intern);
  267. }
  268. /* }}} end dom_element_set_attribute */
  269. /* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-6D6AC0F9
  270. Since:
  271. */
  272. PHP_METHOD(DOMElement, removeAttribute)
  273. {
  274. zval *id;
  275. xmlNodePtr nodep, attrp;
  276. dom_object *intern;
  277. size_t name_len;
  278. char *name;
  279. id = ZEND_THIS;
  280. if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
  281. RETURN_THROWS();
  282. }
  283. DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
  284. if (dom_node_is_read_only(nodep) == SUCCESS) {
  285. php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document));
  286. RETURN_FALSE;
  287. }
  288. attrp = dom_get_dom1_attribute(nodep, (xmlChar *)name);
  289. if (attrp == NULL) {
  290. RETURN_FALSE;
  291. }
  292. switch (attrp->type) {
  293. case XML_ATTRIBUTE_NODE:
  294. if (php_dom_object_get_data(attrp) == NULL) {
  295. node_list_unlink(attrp->children);
  296. xmlUnlinkNode(attrp);
  297. xmlFreeProp((xmlAttrPtr)attrp);
  298. } else {
  299. xmlUnlinkNode(attrp);
  300. }
  301. break;
  302. case XML_NAMESPACE_DECL:
  303. RETURN_FALSE;
  304. default:
  305. break;
  306. }
  307. RETURN_TRUE;
  308. }
  309. /* }}} end dom_element_remove_attribute */
  310. /* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-217A91B8
  311. Since:
  312. */
  313. PHP_METHOD(DOMElement, getAttributeNode)
  314. {
  315. zval *id;
  316. xmlNodePtr nodep, attrp;
  317. size_t name_len;
  318. int ret;
  319. dom_object *intern;
  320. char *name;
  321. id = ZEND_THIS;
  322. if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
  323. RETURN_THROWS();
  324. }
  325. DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
  326. attrp = dom_get_dom1_attribute(nodep, (xmlChar *)name);
  327. if (attrp == NULL) {
  328. RETURN_FALSE;
  329. }
  330. if (attrp->type == XML_NAMESPACE_DECL) {
  331. xmlNsPtr curns;
  332. xmlNodePtr nsparent;
  333. nsparent = attrp->_private;
  334. curns = xmlNewNs(NULL, attrp->name, NULL);
  335. if (attrp->children) {
  336. curns->prefix = xmlStrdup((xmlChar *) attrp->children);
  337. }
  338. if (attrp->children) {
  339. attrp = xmlNewDocNode(nodep->doc, NULL, (xmlChar *) attrp->children, attrp->name);
  340. } else {
  341. attrp = xmlNewDocNode(nodep->doc, NULL, (xmlChar *)"xmlns", attrp->name);
  342. }
  343. attrp->type = XML_NAMESPACE_DECL;
  344. attrp->parent = nsparent;
  345. attrp->ns = curns;
  346. }
  347. DOM_RET_OBJ((xmlNodePtr) attrp, &ret, intern);
  348. }
  349. /* }}} end dom_element_get_attribute_node */
  350. /* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-887236154
  351. Since:
  352. */
  353. PHP_METHOD(DOMElement, setAttributeNode)
  354. {
  355. zval *id, *node;
  356. xmlNode *nodep;
  357. xmlAttr *attrp, *existattrp = NULL;
  358. dom_object *intern, *attrobj, *oldobj;
  359. int ret;
  360. id = ZEND_THIS;
  361. if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &node, dom_attr_class_entry) == FAILURE) {
  362. RETURN_THROWS();
  363. }
  364. DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
  365. if (dom_node_is_read_only(nodep) == SUCCESS) {
  366. php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document));
  367. RETURN_FALSE;
  368. }
  369. DOM_GET_OBJ(attrp, node, xmlAttrPtr, attrobj);
  370. if (attrp->type != XML_ATTRIBUTE_NODE) {
  371. zend_argument_value_error(1, "must have the node attribute");
  372. RETURN_THROWS();
  373. }
  374. if (!(attrp->doc == NULL || attrp->doc == nodep->doc)) {
  375. php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(intern->document));
  376. RETURN_FALSE;
  377. }
  378. existattrp = xmlHasProp(nodep, attrp->name);
  379. if (existattrp != NULL && existattrp->type != XML_ATTRIBUTE_DECL) {
  380. if ((oldobj = php_dom_object_get_data((xmlNodePtr) existattrp)) != NULL &&
  381. ((php_libxml_node_ptr *)oldobj->ptr)->node == (xmlNodePtr) attrp)
  382. {
  383. RETURN_NULL();
  384. }
  385. xmlUnlinkNode((xmlNodePtr) existattrp);
  386. }
  387. if (attrp->parent != NULL) {
  388. xmlUnlinkNode((xmlNodePtr) attrp);
  389. }
  390. if (attrp->doc == NULL && nodep->doc != NULL) {
  391. attrobj->document = intern->document;
  392. php_libxml_increment_doc_ref((php_libxml_node_object *)attrobj, NULL);
  393. }
  394. xmlAddChild(nodep, (xmlNodePtr) attrp);
  395. /* Returns old property if removed otherwise NULL */
  396. if (existattrp != NULL) {
  397. DOM_RET_OBJ((xmlNodePtr) existattrp, &ret, intern);
  398. } else {
  399. RETVAL_NULL();
  400. }
  401. }
  402. /* }}} end dom_element_set_attribute_node */
  403. /* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-D589198
  404. Since:
  405. */
  406. PHP_METHOD(DOMElement, removeAttributeNode)
  407. {
  408. zval *id, *node;
  409. xmlNode *nodep;
  410. xmlAttr *attrp;
  411. dom_object *intern, *attrobj;
  412. int ret;
  413. id = ZEND_THIS;
  414. if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &node, dom_attr_class_entry) == FAILURE) {
  415. RETURN_THROWS();
  416. }
  417. DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
  418. if (dom_node_is_read_only(nodep) == SUCCESS) {
  419. php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document));
  420. RETURN_FALSE;
  421. }
  422. DOM_GET_OBJ(attrp, node, xmlAttrPtr, attrobj);
  423. if (attrp->type != XML_ATTRIBUTE_NODE || attrp->parent != nodep) {
  424. php_dom_throw_error(NOT_FOUND_ERR, dom_get_strict_error(intern->document));
  425. RETURN_FALSE;
  426. }
  427. xmlUnlinkNode((xmlNodePtr) attrp);
  428. DOM_RET_OBJ((xmlNodePtr) attrp, &ret, intern);
  429. }
  430. /* }}} end dom_element_remove_attribute_node */
  431. /* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1938918D
  432. Since:
  433. */
  434. PHP_METHOD(DOMElement, getElementsByTagName)
  435. {
  436. zval *id;
  437. xmlNodePtr elemp;
  438. size_t name_len;
  439. dom_object *intern, *namednode;
  440. char *name;
  441. xmlChar *local;
  442. id = ZEND_THIS;
  443. if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
  444. RETURN_THROWS();
  445. }
  446. DOM_GET_OBJ(elemp, id, xmlNodePtr, intern);
  447. php_dom_create_iterator(return_value, DOM_NODELIST);
  448. namednode = Z_DOMOBJ_P(return_value);
  449. local = xmlCharStrndup(name, name_len);
  450. dom_namednode_iter(intern, 0, namednode, NULL, local, NULL);
  451. }
  452. /* }}} end dom_element_get_elements_by_tag_name */
  453. /* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElGetAttrNS
  454. Since: DOM Level 2
  455. */
  456. PHP_METHOD(DOMElement, getAttributeNS)
  457. {
  458. zval *id;
  459. xmlNodePtr elemp;
  460. xmlNsPtr nsptr;
  461. dom_object *intern;
  462. size_t uri_len = 0, name_len = 0;
  463. char *uri, *name;
  464. xmlChar *strattr;
  465. id = ZEND_THIS;
  466. if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!s", &uri, &uri_len, &name, &name_len) == FAILURE) {
  467. RETURN_THROWS();
  468. }
  469. DOM_GET_OBJ(elemp, id, xmlNodePtr, intern);
  470. strattr = xmlGetNsProp(elemp, (xmlChar *) name, (xmlChar *) uri);
  471. if (strattr != NULL) {
  472. RETVAL_STRING((char *)strattr);
  473. xmlFree(strattr);
  474. } else {
  475. if (xmlStrEqual((xmlChar *) uri, (xmlChar *)DOM_XMLNS_NAMESPACE)) {
  476. nsptr = dom_get_nsdecl(elemp, (xmlChar *)name);
  477. if (nsptr != NULL) {
  478. RETVAL_STRING((char *) nsptr->href);
  479. } else {
  480. RETVAL_EMPTY_STRING();
  481. }
  482. } else {
  483. RETVAL_EMPTY_STRING();
  484. }
  485. }
  486. }
  487. /* }}} end dom_element_get_attribute_ns */
  488. static xmlNsPtr _dom_new_reconNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns) /* {{{ */
  489. {
  490. xmlNsPtr def;
  491. xmlChar prefix[50];
  492. int counter = 1;
  493. if ((tree == NULL) || (ns == NULL) || (ns->type != XML_NAMESPACE_DECL)) {
  494. return NULL;
  495. }
  496. /* Code taken from libxml2 (2.6.20) xmlNewReconciliedNs
  497. *
  498. * Find a close prefix which is not already in use.
  499. * Let's strip namespace prefixes longer than 20 chars !
  500. */
  501. if (ns->prefix == NULL)
  502. snprintf((char *) prefix, sizeof(prefix), "default");
  503. else
  504. snprintf((char *) prefix, sizeof(prefix), "%.20s", (char *)ns->prefix);
  505. def = xmlSearchNs(doc, tree, prefix);
  506. while (def != NULL) {
  507. if (counter > 1000) return(NULL);
  508. if (ns->prefix == NULL)
  509. snprintf((char *) prefix, sizeof(prefix), "default%d", counter++);
  510. else
  511. snprintf((char *) prefix, sizeof(prefix), "%.20s%d",
  512. (char *)ns->prefix, counter++);
  513. def = xmlSearchNs(doc, tree, prefix);
  514. }
  515. /*
  516. * OK, now we are ready to create a new one.
  517. */
  518. def = xmlNewNs(tree, ns->href, prefix);
  519. return(def);
  520. }
  521. /* }}} */
  522. /* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElSetAttrNS
  523. Since: DOM Level 2
  524. */
  525. PHP_METHOD(DOMElement, setAttributeNS)
  526. {
  527. zval *id;
  528. xmlNodePtr elemp, nodep = NULL;
  529. xmlNsPtr nsptr;
  530. xmlAttr *attr;
  531. size_t uri_len = 0, name_len = 0, value_len = 0;
  532. char *uri, *name, *value;
  533. char *localname = NULL, *prefix = NULL;
  534. dom_object *intern;
  535. int errorcode = 0, stricterror, is_xmlns = 0, name_valid;
  536. id = ZEND_THIS;
  537. if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!ss", &uri, &uri_len, &name, &name_len, &value, &value_len) == FAILURE) {
  538. RETURN_THROWS();
  539. }
  540. if (name_len == 0) {
  541. zend_argument_value_error(2, "cannot be empty");
  542. RETURN_THROWS();
  543. }
  544. DOM_GET_OBJ(elemp, id, xmlNodePtr, intern);
  545. stricterror = dom_get_strict_error(intern->document);
  546. if (dom_node_is_read_only(elemp) == SUCCESS) {
  547. php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, stricterror);
  548. RETURN_NULL();
  549. }
  550. errorcode = dom_check_qname(name, &localname, &prefix, uri_len, name_len);
  551. if (errorcode == 0) {
  552. if (uri_len > 0) {
  553. nodep = (xmlNodePtr) xmlHasNsProp(elemp, (xmlChar *) localname, (xmlChar *) uri);
  554. if (nodep != NULL && nodep->type != XML_ATTRIBUTE_DECL) {
  555. node_list_unlink(nodep->children);
  556. }
  557. if ((xmlStrEqual((xmlChar *) prefix, (xmlChar *)"xmlns") ||
  558. (prefix == NULL && xmlStrEqual((xmlChar *) localname, (xmlChar *)"xmlns"))) &&
  559. xmlStrEqual((xmlChar *) uri, (xmlChar *)DOM_XMLNS_NAMESPACE)) {
  560. is_xmlns = 1;
  561. if (prefix == NULL) {
  562. nsptr = dom_get_nsdecl(elemp, NULL);
  563. } else {
  564. nsptr = dom_get_nsdecl(elemp, (xmlChar *)localname);
  565. }
  566. } else {
  567. nsptr = xmlSearchNsByHref(elemp->doc, elemp, (xmlChar *)uri);
  568. if (nsptr && nsptr->prefix == NULL) {
  569. xmlNsPtr tmpnsptr;
  570. tmpnsptr = nsptr->next;
  571. while (tmpnsptr) {
  572. if ((tmpnsptr->prefix != NULL) && (tmpnsptr->href != NULL) &&
  573. (xmlStrEqual(tmpnsptr->href, (xmlChar *) uri))) {
  574. nsptr = tmpnsptr;
  575. break;
  576. }
  577. tmpnsptr = tmpnsptr->next;
  578. }
  579. if (tmpnsptr == NULL) {
  580. nsptr = _dom_new_reconNs(elemp->doc, elemp, nsptr);
  581. }
  582. }
  583. }
  584. if (nsptr == NULL) {
  585. if (prefix == NULL) {
  586. if (is_xmlns == 1) {
  587. xmlNewNs(elemp, (xmlChar *)value, NULL);
  588. xmlReconciliateNs(elemp->doc, elemp);
  589. } else {
  590. errorcode = NAMESPACE_ERR;
  591. }
  592. } else {
  593. if (is_xmlns == 1) {
  594. xmlNewNs(elemp, (xmlChar *)value, (xmlChar *)localname);
  595. } else {
  596. nsptr = dom_get_ns(elemp, uri, &errorcode, prefix);
  597. }
  598. xmlReconciliateNs(elemp->doc, elemp);
  599. }
  600. } else {
  601. if (is_xmlns == 1) {
  602. if (nsptr->href) {
  603. xmlFree((xmlChar *) nsptr->href);
  604. }
  605. nsptr->href = xmlStrdup((xmlChar *)value);
  606. }
  607. }
  608. if (errorcode == 0 && is_xmlns == 0) {
  609. xmlSetNsProp(elemp, nsptr, (xmlChar *)localname, (xmlChar *)value);
  610. }
  611. } else {
  612. name_valid = xmlValidateName((xmlChar *) localname, 0);
  613. if (name_valid != 0) {
  614. errorcode = INVALID_CHARACTER_ERR;
  615. stricterror = 1;
  616. } else {
  617. attr = xmlHasProp(elemp, (xmlChar *)localname);
  618. if (attr != NULL && attr->type != XML_ATTRIBUTE_DECL) {
  619. node_list_unlink(attr->children);
  620. }
  621. xmlSetProp(elemp, (xmlChar *)localname, (xmlChar *)value);
  622. }
  623. }
  624. }
  625. xmlFree(localname);
  626. if (prefix != NULL) {
  627. xmlFree(prefix);
  628. }
  629. if (errorcode != 0) {
  630. php_dom_throw_error(errorcode, stricterror);
  631. }
  632. RETURN_NULL();
  633. }
  634. /* }}} end dom_element_set_attribute_ns */
  635. /* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElRemAtNS
  636. Since: DOM Level 2
  637. */
  638. PHP_METHOD(DOMElement, removeAttributeNS)
  639. {
  640. zval *id;
  641. xmlNode *nodep;
  642. xmlAttr *attrp;
  643. xmlNsPtr nsptr;
  644. dom_object *intern;
  645. size_t name_len, uri_len;
  646. char *name, *uri;
  647. id = ZEND_THIS;
  648. if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!s", &uri, &uri_len, &name, &name_len) == FAILURE) {
  649. RETURN_THROWS();
  650. }
  651. DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
  652. if (dom_node_is_read_only(nodep) == SUCCESS) {
  653. php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document));
  654. RETURN_NULL();
  655. }
  656. attrp = xmlHasNsProp(nodep, (xmlChar *)name, (xmlChar *)uri);
  657. nsptr = dom_get_nsdecl(nodep, (xmlChar *)name);
  658. if (nsptr != NULL) {
  659. if (xmlStrEqual((xmlChar *)uri, nsptr->href)) {
  660. if (nsptr->href != NULL) {
  661. xmlFree((char *) nsptr->href);
  662. nsptr->href = NULL;
  663. }
  664. if (nsptr->prefix != NULL) {
  665. xmlFree((char *) nsptr->prefix);
  666. nsptr->prefix = NULL;
  667. }
  668. } else {
  669. RETURN_NULL();
  670. }
  671. }
  672. if (attrp && attrp->type != XML_ATTRIBUTE_DECL) {
  673. if (php_dom_object_get_data((xmlNodePtr) attrp) == NULL) {
  674. node_list_unlink(attrp->children);
  675. xmlUnlinkNode((xmlNodePtr) attrp);
  676. xmlFreeProp(attrp);
  677. } else {
  678. xmlUnlinkNode((xmlNodePtr) attrp);
  679. }
  680. }
  681. RETURN_NULL();
  682. }
  683. /* }}} end dom_element_remove_attribute_ns */
  684. /* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElGetAtNodeNS
  685. Since: DOM Level 2
  686. */
  687. PHP_METHOD(DOMElement, getAttributeNodeNS)
  688. {
  689. zval *id;
  690. xmlNodePtr elemp, fakeAttrp;
  691. xmlAttrPtr attrp;
  692. dom_object *intern;
  693. size_t uri_len, name_len;
  694. int ret;
  695. char *uri, *name;
  696. id = ZEND_THIS;
  697. if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!s", &uri, &uri_len, &name, &name_len) == FAILURE) {
  698. RETURN_THROWS();
  699. }
  700. DOM_GET_OBJ(elemp, id, xmlNodePtr, intern);
  701. attrp = xmlHasNsProp(elemp, (xmlChar *)name, (xmlChar *)uri);
  702. if (attrp == NULL) {
  703. if (xmlStrEqual((xmlChar *) uri, (xmlChar *)DOM_XMLNS_NAMESPACE)) {
  704. xmlNsPtr nsptr;
  705. nsptr = dom_get_nsdecl(elemp, (xmlChar *)name);
  706. if (nsptr != NULL) {
  707. xmlNsPtr curns;
  708. curns = xmlNewNs(NULL, nsptr->href, NULL);
  709. if (nsptr->prefix) {
  710. curns->prefix = xmlStrdup((xmlChar *) nsptr->prefix);
  711. }
  712. if (nsptr->prefix) {
  713. fakeAttrp = xmlNewDocNode(elemp->doc, NULL, (xmlChar *) nsptr->prefix, nsptr->href);
  714. } else {
  715. fakeAttrp = xmlNewDocNode(elemp->doc, NULL, (xmlChar *)"xmlns", nsptr->href);
  716. }
  717. fakeAttrp->type = XML_NAMESPACE_DECL;
  718. fakeAttrp->parent = elemp;
  719. fakeAttrp->ns = curns;
  720. DOM_RET_OBJ(fakeAttrp, &ret, intern);
  721. } else {
  722. RETURN_NULL();
  723. }
  724. } else {
  725. RETURN_NULL();
  726. }
  727. } else {
  728. DOM_RET_OBJ((xmlNodePtr) attrp, &ret, intern);
  729. }
  730. }
  731. /* }}} end dom_element_get_attribute_node_ns */
  732. /* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElSetAtNodeNS
  733. Since: DOM Level 2
  734. */
  735. PHP_METHOD(DOMElement, setAttributeNodeNS)
  736. {
  737. zval *id, *node;
  738. xmlNode *nodep;
  739. xmlNs *nsp;
  740. xmlAttr *attrp, *existattrp = NULL;
  741. dom_object *intern, *attrobj, *oldobj;
  742. int ret;
  743. id = ZEND_THIS;
  744. if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &node, dom_attr_class_entry) == FAILURE) {
  745. RETURN_THROWS();
  746. }
  747. DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
  748. if (dom_node_is_read_only(nodep) == SUCCESS) {
  749. php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document));
  750. RETURN_FALSE;
  751. }
  752. DOM_GET_OBJ(attrp, node, xmlAttrPtr, attrobj);
  753. /* ZPP Guarantees that a DOMAttr class is given, as it is converted to a xmlAttr
  754. * to pass to libxml (see http://www.xmlsoft.org/html/libxml-tree.html#xmlAttr)
  755. * if it is not of type XML_ATTRIBUTE_NODE it indicates a bug somewhere */
  756. ZEND_ASSERT(attrp->type == XML_ATTRIBUTE_NODE);
  757. if (!(attrp->doc == NULL || attrp->doc == nodep->doc)) {
  758. php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(intern->document));
  759. RETURN_FALSE;
  760. }
  761. nsp = attrp->ns;
  762. if (nsp != NULL) {
  763. existattrp = xmlHasNsProp(nodep, nsp->href, attrp->name);
  764. } else {
  765. existattrp = xmlHasProp(nodep, attrp->name);
  766. }
  767. if (existattrp != NULL && existattrp->type != XML_ATTRIBUTE_DECL) {
  768. if ((oldobj = php_dom_object_get_data((xmlNodePtr) existattrp)) != NULL &&
  769. ((php_libxml_node_ptr *)oldobj->ptr)->node == (xmlNodePtr) attrp)
  770. {
  771. RETURN_NULL();
  772. }
  773. xmlUnlinkNode((xmlNodePtr) existattrp);
  774. }
  775. if (attrp->parent != NULL) {
  776. xmlUnlinkNode((xmlNodePtr) attrp);
  777. }
  778. if (attrp->doc == NULL && nodep->doc != NULL) {
  779. attrobj->document = intern->document;
  780. php_libxml_increment_doc_ref((php_libxml_node_object *)attrobj, NULL);
  781. }
  782. xmlAddChild(nodep, (xmlNodePtr) attrp);
  783. /* Returns old property if removed otherwise NULL */
  784. if (existattrp != NULL) {
  785. DOM_RET_OBJ((xmlNodePtr) existattrp, &ret, intern);
  786. } else {
  787. RETVAL_NULL();
  788. }
  789. }
  790. /* }}} end dom_element_set_attribute_node_ns */
  791. /* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-A6C90942
  792. Since: DOM Level 2
  793. */
  794. PHP_METHOD(DOMElement, getElementsByTagNameNS)
  795. {
  796. zval *id;
  797. xmlNodePtr elemp;
  798. size_t uri_len, name_len;
  799. dom_object *intern, *namednode;
  800. char *uri, *name;
  801. xmlChar *local, *nsuri;
  802. id = ZEND_THIS;
  803. if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!s", &uri, &uri_len, &name, &name_len) == FAILURE) {
  804. RETURN_THROWS();
  805. }
  806. DOM_GET_OBJ(elemp, id, xmlNodePtr, intern);
  807. php_dom_create_iterator(return_value, DOM_NODELIST);
  808. namednode = Z_DOMOBJ_P(return_value);
  809. local = xmlCharStrndup(name, name_len);
  810. nsuri = xmlCharStrndup(uri ? uri : "", uri_len);
  811. dom_namednode_iter(intern, 0, namednode, NULL, local, nsuri);
  812. }
  813. /* }}} end dom_element_get_elements_by_tag_name_ns */
  814. /* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElHasAttr
  815. Since: DOM Level 2
  816. */
  817. PHP_METHOD(DOMElement, hasAttribute)
  818. {
  819. zval *id;
  820. xmlNode *nodep;
  821. dom_object *intern;
  822. char *name;
  823. size_t name_len;
  824. xmlNodePtr attr;
  825. id = ZEND_THIS;
  826. if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
  827. RETURN_THROWS();
  828. }
  829. DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
  830. attr = dom_get_dom1_attribute(nodep, (xmlChar *)name);
  831. if (attr == NULL) {
  832. RETURN_FALSE;
  833. } else {
  834. RETURN_TRUE;
  835. }
  836. }
  837. /* }}} end dom_element_has_attribute */
  838. /* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElHasAttrNS
  839. Since: DOM Level 2
  840. */
  841. PHP_METHOD(DOMElement, hasAttributeNS)
  842. {
  843. zval *id;
  844. xmlNodePtr elemp;
  845. xmlNs *nsp;
  846. dom_object *intern;
  847. size_t uri_len, name_len;
  848. char *uri, *name;
  849. xmlChar *value;
  850. id = ZEND_THIS;
  851. if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!s", &uri, &uri_len, &name, &name_len) == FAILURE) {
  852. RETURN_THROWS();
  853. }
  854. DOM_GET_OBJ(elemp, id, xmlNodePtr, intern);
  855. value = xmlGetNsProp(elemp, (xmlChar *)name, (xmlChar *)uri);
  856. if (value != NULL) {
  857. xmlFree(value);
  858. RETURN_TRUE;
  859. } else {
  860. if (xmlStrEqual((xmlChar *)uri, (xmlChar *)DOM_XMLNS_NAMESPACE)) {
  861. nsp = dom_get_nsdecl(elemp, (xmlChar *)name);
  862. if (nsp != NULL) {
  863. RETURN_TRUE;
  864. }
  865. }
  866. }
  867. RETURN_FALSE;
  868. }
  869. /* }}} end dom_element_has_attribute_ns */
  870. static void php_set_attribute_id(xmlAttrPtr attrp, bool is_id) /* {{{ */
  871. {
  872. if (is_id == 1 && attrp->atype != XML_ATTRIBUTE_ID) {
  873. xmlChar *id_val;
  874. id_val = xmlNodeListGetString(attrp->doc, attrp->children, 1);
  875. if (id_val != NULL) {
  876. xmlAddID(NULL, attrp->doc, id_val, attrp);
  877. xmlFree(id_val);
  878. }
  879. } else if (is_id == 0 && attrp->atype == XML_ATTRIBUTE_ID) {
  880. xmlRemoveID(attrp->doc, attrp);
  881. attrp->atype = 0;
  882. }
  883. }
  884. /* }}} */
  885. /* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElSetIdAttr
  886. Since: DOM Level 3
  887. */
  888. PHP_METHOD(DOMElement, setIdAttribute)
  889. {
  890. zval *id;
  891. xmlNode *nodep;
  892. xmlAttrPtr attrp;
  893. dom_object *intern;
  894. char *name;
  895. size_t name_len;
  896. bool is_id;
  897. id = ZEND_THIS;
  898. if (zend_parse_parameters(ZEND_NUM_ARGS(), "sb", &name, &name_len, &is_id) == FAILURE) {
  899. RETURN_THROWS();
  900. }
  901. DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
  902. if (dom_node_is_read_only(nodep) == SUCCESS) {
  903. php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document));
  904. RETURN_NULL();
  905. }
  906. attrp = xmlHasNsProp(nodep, (xmlChar *)name, NULL);
  907. if (attrp == NULL || attrp->type == XML_ATTRIBUTE_DECL) {
  908. php_dom_throw_error(NOT_FOUND_ERR, dom_get_strict_error(intern->document));
  909. } else {
  910. php_set_attribute_id(attrp, is_id);
  911. }
  912. RETURN_NULL();
  913. }
  914. /* }}} end dom_element_set_id_attribute */
  915. /* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElSetIdAttrNS
  916. Since: DOM Level 3
  917. */
  918. PHP_METHOD(DOMElement, setIdAttributeNS)
  919. {
  920. zval *id;
  921. xmlNodePtr elemp;
  922. xmlAttrPtr attrp;
  923. dom_object *intern;
  924. size_t uri_len, name_len;
  925. char *uri, *name;
  926. bool is_id;
  927. id = ZEND_THIS;
  928. if (zend_parse_parameters(ZEND_NUM_ARGS(), "ssb", &uri, &uri_len, &name, &name_len, &is_id) == FAILURE) {
  929. RETURN_THROWS();
  930. }
  931. DOM_GET_OBJ(elemp, id, xmlNodePtr, intern);
  932. if (dom_node_is_read_only(elemp) == SUCCESS) {
  933. php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document));
  934. RETURN_NULL();
  935. }
  936. attrp = xmlHasNsProp(elemp, (xmlChar *)name, (xmlChar *)uri);
  937. if (attrp == NULL || attrp->type == XML_ATTRIBUTE_DECL) {
  938. php_dom_throw_error(NOT_FOUND_ERR, dom_get_strict_error(intern->document));
  939. } else {
  940. php_set_attribute_id(attrp, is_id);
  941. }
  942. RETURN_NULL();
  943. }
  944. /* }}} end dom_element_set_id_attribute_ns */
  945. /* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-ElSetIdAttrNode
  946. Since: DOM Level 3
  947. */
  948. PHP_METHOD(DOMElement, setIdAttributeNode)
  949. {
  950. zval *id, *node;
  951. xmlNode *nodep;
  952. xmlAttrPtr attrp;
  953. dom_object *intern, *attrobj;
  954. bool is_id;
  955. id = ZEND_THIS;
  956. if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ob", &node, dom_attr_class_entry, &is_id) == FAILURE) {
  957. RETURN_THROWS();
  958. }
  959. DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
  960. if (dom_node_is_read_only(nodep) == SUCCESS) {
  961. php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document));
  962. RETURN_NULL();
  963. }
  964. DOM_GET_OBJ(attrp, node, xmlAttrPtr, attrobj);
  965. if (attrp->parent != nodep) {
  966. php_dom_throw_error(NOT_FOUND_ERR, dom_get_strict_error(intern->document));
  967. } else {
  968. php_set_attribute_id(attrp, is_id);
  969. }
  970. RETURN_NULL();
  971. }
  972. /* }}} end dom_element_set_id_attribute_node */
  973. /* {{{ URL:
  974. Since:
  975. */
  976. PHP_METHOD(DOMElement, remove)
  977. {
  978. zval *id;
  979. xmlNodePtr child;
  980. dom_object *intern;
  981. if (zend_parse_parameters_none() == FAILURE) {
  982. RETURN_THROWS();
  983. }
  984. id = ZEND_THIS;
  985. DOM_GET_OBJ(child, id, xmlNodePtr, intern);
  986. dom_child_node_remove(intern);
  987. }
  988. /* }}} end DOMElement::remove */
  989. PHP_METHOD(DOMElement, after)
  990. {
  991. int argc;
  992. zval *args, *id;
  993. dom_object *intern;
  994. xmlNode *context;
  995. if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
  996. RETURN_THROWS();
  997. }
  998. id = ZEND_THIS;
  999. DOM_GET_OBJ(context, id, xmlNodePtr, intern);
  1000. dom_parent_node_after(intern, args, argc);
  1001. }
  1002. PHP_METHOD(DOMElement, before)
  1003. {
  1004. int argc;
  1005. zval *args, *id;
  1006. dom_object *intern;
  1007. xmlNode *context;
  1008. if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
  1009. RETURN_THROWS();
  1010. }
  1011. id = ZEND_THIS;
  1012. DOM_GET_OBJ(context, id, xmlNodePtr, intern);
  1013. dom_parent_node_before(intern, args, argc);
  1014. }
  1015. /* {{{ URL: https://dom.spec.whatwg.org/#dom-parentnode-append
  1016. Since: DOM Living Standard (DOM4)
  1017. */
  1018. PHP_METHOD(DOMElement, append)
  1019. {
  1020. int argc;
  1021. zval *args, *id;
  1022. dom_object *intern;
  1023. xmlNode *context;
  1024. if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
  1025. RETURN_THROWS();
  1026. }
  1027. id = ZEND_THIS;
  1028. DOM_GET_OBJ(context, id, xmlNodePtr, intern);
  1029. dom_parent_node_append(intern, args, argc);
  1030. }
  1031. /* }}} end DOMElement::append */
  1032. /* {{{ URL: https://dom.spec.whatwg.org/#dom-parentnode-prepend
  1033. Since: DOM Living Standard (DOM4)
  1034. */
  1035. PHP_METHOD(DOMElement, prepend)
  1036. {
  1037. int argc;
  1038. zval *args, *id;
  1039. dom_object *intern;
  1040. xmlNode *context;
  1041. if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
  1042. RETURN_THROWS();
  1043. }
  1044. id = ZEND_THIS;
  1045. DOM_GET_OBJ(context, id, xmlNodePtr, intern);
  1046. dom_parent_node_prepend(intern, args, argc);
  1047. }
  1048. /* }}} end DOMElement::prepend */
  1049. /* {{{ URL: https://dom.spec.whatwg.org/#dom-parentnode-prepend
  1050. Since: DOM Living Standard (DOM4)
  1051. */
  1052. PHP_METHOD(DOMElement, replaceWith)
  1053. {
  1054. int argc;
  1055. zval *args, *id;
  1056. dom_object *intern;
  1057. xmlNode *context;
  1058. if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
  1059. RETURN_THROWS();
  1060. }
  1061. id = ZEND_THIS;
  1062. DOM_GET_OBJ(context, id, xmlNodePtr, intern);
  1063. dom_parent_node_after(intern, args, argc);
  1064. dom_child_node_remove(intern);
  1065. }
  1066. /* }}} end DOMElement::prepend */
  1067. #endif