12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267 |
- /*
- +----------------------------------------------------------------------+
- | PHP Version 7 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2018 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 3.01 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available through the world-wide-web at the following url: |
- | http://www.php.net/license/3_01.txt |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Christian Stocker <chregu@php.net> |
- | Rob Richards <rrichards@php.net> |
- +----------------------------------------------------------------------+
- */
- #ifdef HAVE_CONFIG_H
- #include "config.h"
- #endif
- #include "php.h"
- #if HAVE_LIBXML && HAVE_DOM
- #include "php_dom.h"
- #include <libxml/SAX.h>
- #ifdef LIBXML_SCHEMAS_ENABLED
- #include <libxml/relaxng.h>
- #include <libxml/xmlschemas.h>
- #endif
- typedef struct _idsIterator idsIterator;
- struct _idsIterator {
- xmlChar *elementId;
- xmlNode *element;
- };
- #define DOM_LOAD_STRING 0
- #define DOM_LOAD_FILE 1
- /* {{{ arginfo */
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_element, 0, 0, 1)
- ZEND_ARG_INFO(0, tagName)
- ZEND_ARG_INFO(0, value)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_document_fragment, 0, 0, 0)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_text_node, 0, 0, 1)
- ZEND_ARG_INFO(0, data)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_comment, 0, 0, 1)
- ZEND_ARG_INFO(0, data)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_cdatasection, 0, 0, 1)
- ZEND_ARG_INFO(0, data)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_processing_instruction, 0, 0, 2)
- ZEND_ARG_INFO(0, target)
- ZEND_ARG_INFO(0, data)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_attribute, 0, 0, 1)
- ZEND_ARG_INFO(0, name)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_entity_reference, 0, 0, 1)
- ZEND_ARG_INFO(0, name)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_get_elements_by_tag_name, 0, 0, 1)
- ZEND_ARG_INFO(0, tagName)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_import_node, 0, 0, 2)
- ZEND_ARG_OBJ_INFO(0, importedNode, DOMNode, 0)
- ZEND_ARG_INFO(0, deep)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_element_ns, 0, 0, 2)
- ZEND_ARG_INFO(0, namespaceURI)
- ZEND_ARG_INFO(0, qualifiedName)
- ZEND_ARG_INFO(0, value)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_attribute_ns, 0, 0, 2)
- ZEND_ARG_INFO(0, namespaceURI)
- ZEND_ARG_INFO(0, qualifiedName)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_get_elements_by_tag_name_ns, 0, 0, 2)
- ZEND_ARG_INFO(0, namespaceURI)
- ZEND_ARG_INFO(0, localName)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_get_element_by_id, 0, 0, 1)
- ZEND_ARG_INFO(0, elementId)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_adopt_node, 0, 0, 1)
- ZEND_ARG_OBJ_INFO(0, source, DOMNode, 0)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_normalize_document, 0, 0, 0)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_rename_node, 0, 0, 3)
- ZEND_ARG_OBJ_INFO(0, node, DOMNode, 0)
- ZEND_ARG_INFO(0, namespaceURI)
- ZEND_ARG_INFO(0, qualifiedName)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_load, 0, 0, 1)
- ZEND_ARG_INFO(0, source)
- ZEND_ARG_INFO(0, options)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_save, 0, 0, 1)
- ZEND_ARG_INFO(0, file)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_loadxml, 0, 0, 1)
- ZEND_ARG_INFO(0, source)
- ZEND_ARG_INFO(0, options)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_savexml, 0, 0, 0)
- ZEND_ARG_OBJ_INFO(0, node, DOMNode, 1)
- ZEND_ARG_INFO(0, options)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_construct, 0, 0, 0)
- ZEND_ARG_INFO(0, version)
- ZEND_ARG_INFO(0, encoding)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_validate, 0, 0, 0)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_xinclude, 0, 0, 0)
- ZEND_ARG_INFO(0, options)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_loadhtml, 0, 0, 1)
- ZEND_ARG_INFO(0, source)
- ZEND_ARG_INFO(0, options)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_loadhtmlfile, 0, 0, 1)
- ZEND_ARG_INFO(0, source)
- ZEND_ARG_INFO(0, options)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_savehtml, 0, 0, 0)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_savehtmlfile, 0, 0, 1)
- ZEND_ARG_INFO(0, file)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_schema_validate_file, 0, 0, 1)
- ZEND_ARG_INFO(0, filename)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_schema_validate_xml, 0, 0, 1)
- ZEND_ARG_INFO(0, source)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_relaxNG_validate_file, 0, 0, 1)
- ZEND_ARG_INFO(0, filename)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_relaxNG_validate_xml, 0, 0, 1)
- ZEND_ARG_INFO(0, source)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_registernodeclass, 0, 0, 2)
- ZEND_ARG_INFO(0, baseClass)
- ZEND_ARG_INFO(0, extendedClass)
- ZEND_END_ARG_INFO();
- /* }}} */
- /*
- * class DOMDocument extends DOMNode
- *
- * URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-i-Document
- * Since:
- */
- const zend_function_entry php_dom_document_class_functions[] = { /* {{{ */
- PHP_FALIAS(createElement, dom_document_create_element, arginfo_dom_document_create_element)
- PHP_FALIAS(createDocumentFragment, dom_document_create_document_fragment, arginfo_dom_document_create_document_fragment)
- PHP_FALIAS(createTextNode, dom_document_create_text_node, arginfo_dom_document_create_text_node)
- PHP_FALIAS(createComment, dom_document_create_comment, arginfo_dom_document_create_comment)
- PHP_FALIAS(createCDATASection, dom_document_create_cdatasection, arginfo_dom_document_create_cdatasection)
- PHP_FALIAS(createProcessingInstruction, dom_document_create_processing_instruction, arginfo_dom_document_create_processing_instruction)
- PHP_FALIAS(createAttribute, dom_document_create_attribute, arginfo_dom_document_create_attribute)
- PHP_FALIAS(createEntityReference, dom_document_create_entity_reference, arginfo_dom_document_create_entity_reference)
- PHP_FALIAS(getElementsByTagName, dom_document_get_elements_by_tag_name, arginfo_dom_document_get_elements_by_tag_name)
- PHP_FALIAS(importNode, dom_document_import_node, arginfo_dom_document_import_node)
- PHP_FALIAS(createElementNS, dom_document_create_element_ns, arginfo_dom_document_create_element_ns)
- PHP_FALIAS(createAttributeNS, dom_document_create_attribute_ns, arginfo_dom_document_create_attribute_ns)
- PHP_FALIAS(getElementsByTagNameNS, dom_document_get_elements_by_tag_name_ns, arginfo_dom_document_get_elements_by_tag_name_ns)
- PHP_FALIAS(getElementById, dom_document_get_element_by_id, arginfo_dom_document_get_element_by_id)
- PHP_FALIAS(adoptNode, dom_document_adopt_node, arginfo_dom_document_adopt_node)
- PHP_FALIAS(normalizeDocument, dom_document_normalize_document, arginfo_dom_document_normalize_document)
- PHP_FALIAS(renameNode, dom_document_rename_node, arginfo_dom_document_rename_node)
- PHP_ME(domdocument, load, arginfo_dom_document_load, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
- PHP_FALIAS(save, dom_document_save, arginfo_dom_document_save)
- PHP_ME(domdocument, loadXML, arginfo_dom_document_loadxml, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
- PHP_FALIAS(saveXML, dom_document_savexml, arginfo_dom_document_savexml)
- PHP_ME(domdocument, __construct, arginfo_dom_document_construct, ZEND_ACC_PUBLIC)
- PHP_FALIAS(validate, dom_document_validate, arginfo_dom_document_validate)
- PHP_FALIAS(xinclude, dom_document_xinclude, arginfo_dom_document_xinclude)
- #if defined(LIBXML_HTML_ENABLED)
- PHP_ME(domdocument, loadHTML, arginfo_dom_document_loadhtml, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
- PHP_ME(domdocument, loadHTMLFile, arginfo_dom_document_loadhtmlfile, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
- PHP_FALIAS(saveHTML, dom_document_save_html, arginfo_dom_document_savehtml)
- PHP_FALIAS(saveHTMLFile, dom_document_save_html_file, arginfo_dom_document_savehtmlfile)
- #endif /* defined(LIBXML_HTML_ENABLED) */
- #if defined(LIBXML_SCHEMAS_ENABLED)
- PHP_FALIAS(schemaValidate, dom_document_schema_validate_file, arginfo_dom_document_schema_validate_file)
- PHP_FALIAS(schemaValidateSource, dom_document_schema_validate_xml, arginfo_dom_document_schema_validate_xml)
- PHP_FALIAS(relaxNGValidate, dom_document_relaxNG_validate_file, arginfo_dom_document_relaxNG_validate_file)
- PHP_FALIAS(relaxNGValidateSource, dom_document_relaxNG_validate_xml, arginfo_dom_document_relaxNG_validate_xml)
- #endif
- PHP_ME(domdocument, registerNodeClass, arginfo_dom_document_registernodeclass, ZEND_ACC_PUBLIC)
- PHP_FE_END
- };
- /* }}} */
- /* {{{ docType DOMDocumentType
- readonly=yes
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-B63ED1A31
- Since:
- */
- int dom_document_doctype_read(dom_object *obj, zval *retval)
- {
- xmlDoc *docp = (xmlDocPtr) dom_object_get_node(obj);
- xmlDtdPtr dtdptr;
- if (docp == NULL) {
- php_dom_throw_error(INVALID_STATE_ERR, 0);
- return FAILURE;
- }
- dtdptr = xmlGetIntSubset(docp);
- if (!dtdptr) {
- ZVAL_NULL(retval);
- return SUCCESS;
- }
- php_dom_create_object((xmlNodePtr) dtdptr, retval, obj);
- return SUCCESS;
- }
- /* }}} */
- /* {{{ implementation DOMImplementation
- readonly=yes
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1B793EBA
- Since:
- */
- int dom_document_implementation_read(dom_object *obj, zval *retval)
- {
- php_dom_create_implementation(retval);
- return SUCCESS;
- }
- /* }}} */
- /* {{{ documentElement DOMElement
- readonly=yes
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-87CD092
- Since:
- */
- int dom_document_document_element_read(dom_object *obj, zval *retval)
- {
- xmlDoc *docp = (xmlDocPtr) dom_object_get_node(obj);
- xmlNode *root;
- if (docp == NULL) {
- php_dom_throw_error(INVALID_STATE_ERR, 0);
- return FAILURE;
- }
- root = xmlDocGetRootElement(docp);
- if (!root) {
- ZVAL_NULL(retval);
- return SUCCESS;
- }
- php_dom_create_object(root, retval, obj);
- return SUCCESS;
- }
- /* }}} */
- /* {{{ encoding string
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-encoding
- Since: DOM Level 3
- */
- int dom_document_encoding_read(dom_object *obj, zval *retval)
- {
- xmlDoc *docp = (xmlDocPtr) dom_object_get_node(obj);
- char *encoding;
- if (docp == NULL) {
- php_dom_throw_error(INVALID_STATE_ERR, 0);
- return FAILURE;
- }
- encoding = (char *) docp->encoding;
- if (encoding != NULL) {
- ZVAL_STRING(retval, encoding);
- } else {
- ZVAL_NULL(retval);
- }
- return SUCCESS;
- }
- int dom_document_encoding_write(dom_object *obj, zval *newval)
- {
- xmlDoc *docp = (xmlDocPtr) dom_object_get_node(obj);
- zend_string *str;
- xmlCharEncodingHandlerPtr handler;
- if (docp == NULL) {
- php_dom_throw_error(INVALID_STATE_ERR, 0);
- return FAILURE;
- }
- str = zval_get_string(newval);
- handler = xmlFindCharEncodingHandler(ZSTR_VAL(str));
- if (handler != NULL) {
- xmlCharEncCloseFunc(handler);
- if (docp->encoding != NULL) {
- xmlFree((xmlChar *)docp->encoding);
- }
- docp->encoding = xmlStrdup((const xmlChar *) ZSTR_VAL(str));
- } else {
- php_error_docref(NULL, E_WARNING, "Invalid Document Encoding");
- }
- zend_string_release_ex(str, 0);
- return SUCCESS;
- }
- /* }}} */
- /* {{{ standalone boolean
- readonly=no
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-standalone
- Since: DOM Level 3
- */
- int dom_document_standalone_read(dom_object *obj, zval *retval)
- {
- xmlDoc *docp;
- docp = (xmlDocPtr) dom_object_get_node(obj);
- if (docp == NULL) {
- php_dom_throw_error(INVALID_STATE_ERR, 0);
- return FAILURE;
- }
- ZVAL_BOOL(retval, docp->standalone);
- return SUCCESS;
- }
- int dom_document_standalone_write(dom_object *obj, zval *newval)
- {
- xmlDoc *docp = (xmlDocPtr) dom_object_get_node(obj);
- zend_long standalone;
- if (docp == NULL) {
- php_dom_throw_error(INVALID_STATE_ERR, 0);
- return FAILURE;
- }
- standalone = zval_get_long(newval);
- docp->standalone = ZEND_NORMALIZE_BOOL(standalone);
- return SUCCESS;
- }
- /* }}} */
- /* {{{ version string
- readonly=no
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-version
- Since: DOM Level 3
- */
- int dom_document_version_read(dom_object *obj, zval *retval)
- {
- xmlDoc *docp = (xmlDocPtr) dom_object_get_node(obj);
- char *version;
- if (docp == NULL) {
- php_dom_throw_error(INVALID_STATE_ERR, 0);
- return FAILURE;
- }
- version = (char *) docp->version;
- if (version != NULL) {
- ZVAL_STRING(retval, version);
- } else {
- ZVAL_NULL(retval);
- }
- return SUCCESS;
- }
- int dom_document_version_write(dom_object *obj, zval *newval)
- {
- xmlDoc *docp = (xmlDocPtr) dom_object_get_node(obj);
- zend_string *str;
- if (docp == NULL) {
- php_dom_throw_error(INVALID_STATE_ERR, 0);
- return FAILURE;
- }
- if (docp->version != NULL) {
- xmlFree((xmlChar *) docp->version );
- }
- str = zval_get_string(newval);
- docp->version = xmlStrdup((const xmlChar *) ZSTR_VAL(str));
- zend_string_release_ex(str, 0);
- return SUCCESS;
- }
- /* }}} */
- /* {{{ strictErrorChecking boolean
- readonly=no
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-strictErrorChecking
- Since: DOM Level 3
- */
- int dom_document_strict_error_checking_read(dom_object *obj, zval *retval)
- {
- if (obj->document) {
- dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
- ZVAL_BOOL(retval, doc_prop->stricterror);
- } else {
- ZVAL_FALSE(retval);
- }
- return SUCCESS;
- }
- int dom_document_strict_error_checking_write(dom_object *obj, zval *newval)
- {
- if (obj->document) {
- dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
- doc_prop->stricterror = zend_is_true(newval);
- }
- return SUCCESS;
- }
- /* }}} */
- /* {{{ formatOutput boolean
- readonly=no
- */
- int dom_document_format_output_read(dom_object *obj, zval *retval)
- {
- if (obj->document) {
- dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
- ZVAL_BOOL(retval, doc_prop->formatoutput);
- } else {
- ZVAL_FALSE(retval);
- }
- return SUCCESS;
- }
- int dom_document_format_output_write(dom_object *obj, zval *newval)
- {
- if (obj->document) {
- dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
- doc_prop->formatoutput = zend_is_true(newval);
- }
- return SUCCESS;
- }
- /* }}} */
- /* {{{ validateOnParse boolean
- readonly=no
- */
- int dom_document_validate_on_parse_read(dom_object *obj, zval *retval)
- {
- if (obj->document) {
- dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
- ZVAL_BOOL(retval, doc_prop->validateonparse);
- } else {
- ZVAL_FALSE(retval);
- }
- return SUCCESS;
- }
- int dom_document_validate_on_parse_write(dom_object *obj, zval *newval)
- {
- if (obj->document) {
- dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
- doc_prop->validateonparse = zend_is_true(newval);
- }
- return SUCCESS;
- }
- /* }}} */
- /* {{{ resolveExternals boolean
- readonly=no
- */
- int dom_document_resolve_externals_read(dom_object *obj, zval *retval)
- {
- if (obj->document) {
- dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
- ZVAL_BOOL(retval, doc_prop->resolveexternals);
- } else {
- ZVAL_FALSE(retval);
- }
- return SUCCESS;
- }
- int dom_document_resolve_externals_write(dom_object *obj, zval *newval)
- {
- if (obj->document) {
- dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
- doc_prop->resolveexternals = zend_is_true(newval);
- }
- return SUCCESS;
- }
- /* }}} */
- /* {{{ preserveWhiteSpace boolean
- readonly=no
- */
- int dom_document_preserve_whitespace_read(dom_object *obj, zval *retval)
- {
- if (obj->document) {
- dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
- ZVAL_BOOL(retval, doc_prop->preservewhitespace);
- } else {
- ZVAL_FALSE(retval);
- }
- return SUCCESS;
- }
- int dom_document_preserve_whitespace_write(dom_object *obj, zval *newval)
- {
- if (obj->document) {
- dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
- doc_prop->preservewhitespace = zend_is_true(newval);
- }
- return SUCCESS;
- }
- /* }}} */
- /* {{{ recover boolean
- readonly=no
- */
- int dom_document_recover_read(dom_object *obj, zval *retval)
- {
- if (obj->document) {
- dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
- ZVAL_BOOL(retval, doc_prop->recover);
- } else {
- ZVAL_FALSE(retval);
- }
- return SUCCESS;
- }
- int dom_document_recover_write(dom_object *obj, zval *newval)
- {
- if (obj->document) {
- dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
- doc_prop->recover = zend_is_true(newval);
- }
- return SUCCESS;
- }
- /* }}} */
- /* {{{ substituteEntities boolean
- readonly=no
- */
- int dom_document_substitue_entities_read(dom_object *obj, zval *retval)
- {
- if (obj->document) {
- dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
- ZVAL_BOOL(retval, doc_prop->substituteentities);
- } else {
- ZVAL_FALSE(retval);
- }
- return SUCCESS;
- }
- int dom_document_substitue_entities_write(dom_object *obj, zval *newval)
- {
- if (obj->document) {
- dom_doc_propsptr doc_prop = dom_get_doc_props(obj->document);
- doc_prop->substituteentities = zend_is_true(newval);
- }
- return SUCCESS;
- }
- /* }}} */
- /* {{{ documentURI string
- readonly=no
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-documentURI
- Since: DOM Level 3
- */
- int dom_document_document_uri_read(dom_object *obj, zval *retval)
- {
- xmlDoc *docp = (xmlDocPtr) dom_object_get_node(obj);
- char *url;
- if (docp == NULL) {
- php_dom_throw_error(INVALID_STATE_ERR, 0);
- return FAILURE;
- }
- url = (char *) docp->URL;
- if (url != NULL) {
- ZVAL_STRING(retval, url);
- } else {
- ZVAL_NULL(retval);
- }
- return SUCCESS;
- }
- int dom_document_document_uri_write(dom_object *obj, zval *newval)
- {
- xmlDoc *docp = (xmlDocPtr) dom_object_get_node(obj);
- zend_string *str;
- if (docp == NULL) {
- php_dom_throw_error(INVALID_STATE_ERR, 0);
- return FAILURE;
- }
- if (docp->URL != NULL) {
- xmlFree((xmlChar *) docp->URL);
- }
- str = zval_get_string(newval);
- docp->URL = xmlStrdup((const xmlChar *) ZSTR_VAL(str));
- zend_string_release_ex(str, 0);
- return SUCCESS;
- }
- /* }}} */
- /* {{{ config DOMConfiguration
- readonly=yes
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-config
- Since: DOM Level 3
- */
- int dom_document_config_read(dom_object *obj, zval *retval)
- {
- ZVAL_NULL(retval);
- return SUCCESS;
- }
- /* }}} */
- /* {{{ proto DOMElement dom_document_create_element(string tagName [, string value])
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-2141741547
- Since:
- */
- PHP_FUNCTION(dom_document_create_element)
- {
- zval *id;
- xmlNode *node;
- xmlDocPtr docp;
- dom_object *intern;
- int ret;
- size_t name_len, value_len;
- char *name, *value = NULL;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os|s", &id, dom_document_class_entry, &name, &name_len, &value, &value_len) == FAILURE) {
- return;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- if (xmlValidateName((xmlChar *) name, 0) != 0) {
- php_dom_throw_error(INVALID_CHARACTER_ERR, dom_get_strict_error(intern->document));
- RETURN_FALSE;
- }
- node = xmlNewDocNode(docp, NULL, (xmlChar *) name, (xmlChar *) value);
- if (!node) {
- RETURN_FALSE;
- }
- DOM_RET_OBJ(node, &ret, intern);
- }
- /* }}} end dom_document_create_element */
- /* {{{ proto DOMDocumentFragment dom_document_create_document_fragment()
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-35CB04B5
- Since:
- */
- PHP_FUNCTION(dom_document_create_document_fragment)
- {
- zval *id;
- xmlNode *node;
- xmlDocPtr docp;
- dom_object *intern;
- int ret;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &id, dom_document_class_entry) == FAILURE) {
- return;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- node = xmlNewDocFragment(docp);
- if (!node) {
- RETURN_FALSE;
- }
- DOM_RET_OBJ(node, &ret, intern);
- }
- /* }}} end dom_document_create_document_fragment */
- /* {{{ proto DOMText dom_document_create_text_node(string data)
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1975348127
- Since:
- */
- PHP_FUNCTION(dom_document_create_text_node)
- {
- zval *id;
- xmlNode *node;
- xmlDocPtr docp;
- int ret;
- size_t value_len;
- dom_object *intern;
- char *value;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &id, dom_document_class_entry, &value, &value_len) == FAILURE) {
- return;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- node = xmlNewDocText(docp, (xmlChar *) value);
- if (!node) {
- RETURN_FALSE;
- }
- DOM_RET_OBJ(node, &ret, intern);
- }
- /* }}} end dom_document_create_text_node */
- /* {{{ proto DOMComment dom_document_create_comment(string data)
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1334481328
- Since:
- */
- PHP_FUNCTION(dom_document_create_comment)
- {
- zval *id;
- xmlNode *node;
- xmlDocPtr docp;
- int ret;
- size_t value_len;
- dom_object *intern;
- char *value;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &id, dom_document_class_entry, &value, &value_len) == FAILURE) {
- return;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- node = xmlNewDocComment(docp, (xmlChar *) value);
- if (!node) {
- RETURN_FALSE;
- }
- DOM_RET_OBJ(node, &ret, intern);
- }
- /* }}} end dom_document_create_comment */
- /* {{{ proto DOMCdataSection dom_document_create_cdatasection(string data)
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-D26C0AF8
- Since:
- */
- PHP_FUNCTION(dom_document_create_cdatasection)
- {
- zval *id;
- xmlNode *node;
- xmlDocPtr docp;
- int ret;
- size_t value_len;
- dom_object *intern;
- char *value;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &id, dom_document_class_entry, &value, &value_len) == FAILURE) {
- return;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- node = xmlNewCDataBlock(docp, (xmlChar *) value, value_len);
- if (!node) {
- RETURN_FALSE;
- }
- DOM_RET_OBJ(node, &ret, intern);
- }
- /* }}} end dom_document_create_cdatasection */
- /* {{{ proto DOMProcessingInstruction dom_document_create_processing_instruction(string target, string data)
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-135944439
- Since:
- */
- PHP_FUNCTION(dom_document_create_processing_instruction)
- {
- zval *id;
- xmlNode *node;
- xmlDocPtr docp;
- int ret;
- size_t value_len, name_len = 0;
- dom_object *intern;
- char *name, *value = NULL;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os|s", &id, dom_document_class_entry, &name, &name_len, &value, &value_len) == FAILURE) {
- return;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- if (xmlValidateName((xmlChar *) name, 0) != 0) {
- php_dom_throw_error(INVALID_CHARACTER_ERR, dom_get_strict_error(intern->document));
- RETURN_FALSE;
- }
- node = xmlNewPI((xmlChar *) name, (xmlChar *) value);
- if (!node) {
- RETURN_FALSE;
- }
- node->doc = docp;
- DOM_RET_OBJ(node, &ret, intern);
- }
- /* }}} end dom_document_create_processing_instruction */
- /* {{{ proto DOMAttr dom_document_create_attribute(string name)
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1084891198
- Since:
- */
- PHP_FUNCTION(dom_document_create_attribute)
- {
- zval *id;
- xmlAttrPtr node;
- xmlDocPtr docp;
- int ret;
- size_t name_len;
- dom_object *intern;
- char *name;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &id, dom_document_class_entry, &name, &name_len) == FAILURE) {
- return;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- if (xmlValidateName((xmlChar *) name, 0) != 0) {
- php_dom_throw_error(INVALID_CHARACTER_ERR, dom_get_strict_error(intern->document));
- RETURN_FALSE;
- }
- node = xmlNewDocProp(docp, (xmlChar *) name, NULL);
- if (!node) {
- RETURN_FALSE;
- }
- DOM_RET_OBJ((xmlNodePtr) node, &ret, intern);
- }
- /* }}} end dom_document_create_attribute */
- /* {{{ proto DOMEntityReference dom_document_create_entity_reference(string name)
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-392B75AE
- Since:
- */
- PHP_FUNCTION(dom_document_create_entity_reference)
- {
- zval *id;
- xmlNode *node;
- xmlDocPtr docp = NULL;
- dom_object *intern;
- int ret;
- size_t name_len;
- char *name;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &id, dom_document_class_entry, &name, &name_len) == FAILURE) {
- return;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- if (xmlValidateName((xmlChar *) name, 0) != 0) {
- php_dom_throw_error(INVALID_CHARACTER_ERR, dom_get_strict_error(intern->document));
- RETURN_FALSE;
- }
- node = xmlNewReference(docp, (xmlChar *) name);
- if (!node) {
- RETURN_FALSE;
- }
- DOM_RET_OBJ((xmlNodePtr) node, &ret, intern);
- }
- /* }}} end dom_document_create_entity_reference */
- /* {{{ proto DOMNodeList dom_document_get_elements_by_tag_name(string tagname)
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-A6C9094
- Since:
- */
- PHP_FUNCTION(dom_document_get_elements_by_tag_name)
- {
- zval *id;
- xmlDocPtr docp;
- size_t name_len;
- dom_object *intern, *namednode;
- char *name;
- xmlChar *local;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &id, dom_document_class_entry, &name, &name_len) == FAILURE) {
- return;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- php_dom_create_interator(return_value, DOM_NODELIST);
- namednode = Z_DOMOBJ_P(return_value);
- local = xmlCharStrndup(name, name_len);
- dom_namednode_iter(intern, 0, namednode, NULL, local, NULL);
- }
- /* }}} end dom_document_get_elements_by_tag_name */
- /* {{{ proto DOMNode dom_document_import_node(DOMNode importedNode, bool deep)
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Core-Document-importNode
- Since: DOM Level 2
- */
- PHP_FUNCTION(dom_document_import_node)
- {
- zval *id, *node;
- xmlDocPtr docp;
- xmlNodePtr nodep, retnodep;
- dom_object *intern, *nodeobj;
- int ret;
- zend_bool recursive = 0;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "OO|b", &id, dom_document_class_entry, &node, dom_node_class_entry, &recursive) == FAILURE) {
- return;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- DOM_GET_OBJ(nodep, node, xmlNodePtr, nodeobj);
- if (nodep->type == XML_HTML_DOCUMENT_NODE || nodep->type == XML_DOCUMENT_NODE
- || nodep->type == XML_DOCUMENT_TYPE_NODE) {
- php_error_docref(NULL, E_WARNING, "Cannot import: Node Type Not Supported");
- RETURN_FALSE;
- }
- if (nodep->doc == docp) {
- retnodep = nodep;
- } else {
- if ((recursive == 0) && (nodep->type == XML_ELEMENT_NODE)) {
- recursive = 2;
- }
- retnodep = xmlDocCopyNode(nodep, docp, recursive);
- if (!retnodep) {
- RETURN_FALSE;
- }
- if ((retnodep->type == XML_ATTRIBUTE_NODE) && (nodep->ns != NULL)) {
- xmlNsPtr nsptr = NULL;
- xmlNodePtr root = xmlDocGetRootElement(docp);
- nsptr = xmlSearchNsByHref (nodep->doc, root, nodep->ns->href);
- if (nsptr == NULL) {
- int errorcode;
- nsptr = dom_get_ns(root, (char *) nodep->ns->href, &errorcode, (char *) nodep->ns->prefix);
- }
- xmlSetNs(retnodep, nsptr);
- }
- }
- DOM_RET_OBJ((xmlNodePtr) retnodep, &ret, intern);
- }
- /* }}} end dom_document_import_node */
- /* {{{ proto DOMElement dom_document_create_element_ns(string namespaceURI, string qualifiedName [,string value])
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-DocCrElNS
- Since: DOM Level 2
- */
- PHP_FUNCTION(dom_document_create_element_ns)
- {
- zval *id;
- xmlDocPtr docp;
- xmlNodePtr nodep = NULL;
- xmlNsPtr nsptr = NULL;
- int ret;
- size_t uri_len = 0, name_len = 0, value_len = 0;
- char *uri, *name, *value = NULL;
- char *localname = NULL, *prefix = NULL;
- int errorcode;
- dom_object *intern;
- 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) {
- return;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- errorcode = dom_check_qname(name, &localname, &prefix, uri_len, name_len);
- if (errorcode == 0) {
- if (xmlValidateName((xmlChar *) localname, 0) == 0) {
- nodep = xmlNewDocNode(docp, NULL, (xmlChar *) localname, (xmlChar *) value);
- if (nodep != NULL && uri != NULL) {
- nsptr = xmlSearchNsByHref(nodep->doc, nodep, (xmlChar *) uri);
- if (nsptr == NULL) {
- nsptr = dom_get_ns(nodep, uri, &errorcode, prefix);
- }
- xmlSetNs(nodep, nsptr);
- }
- } else {
- errorcode = INVALID_CHARACTER_ERR;
- }
- }
- xmlFree(localname);
- if (prefix != NULL) {
- xmlFree(prefix);
- }
- if (errorcode != 0) {
- if (nodep != NULL) {
- xmlFreeNode(nodep);
- }
- php_dom_throw_error(errorcode, dom_get_strict_error(intern->document));
- RETURN_FALSE;
- }
- if (nodep == NULL) {
- RETURN_FALSE;
- }
- nodep->ns = nsptr;
- DOM_RET_OBJ(nodep, &ret, intern);
- }
- /* }}} end dom_document_create_element_ns */
- /* {{{ proto DOMAttr dom_document_create_attribute_ns(string namespaceURI, string qualifiedName)
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-DocCrAttrNS
- Since: DOM Level 2
- */
- PHP_FUNCTION(dom_document_create_attribute_ns)
- {
- zval *id;
- xmlDocPtr docp;
- xmlNodePtr nodep = NULL, root;
- xmlNsPtr nsptr;
- int ret;
- size_t uri_len = 0, name_len = 0;
- char *uri, *name;
- char *localname = NULL, *prefix = NULL;
- dom_object *intern;
- int errorcode;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os!s", &id, dom_document_class_entry, &uri, &uri_len, &name, &name_len) == FAILURE) {
- return;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- root = xmlDocGetRootElement(docp);
- if (root != NULL) {
- errorcode = dom_check_qname(name, &localname, &prefix, uri_len, name_len);
- if (errorcode == 0) {
- if (xmlValidateName((xmlChar *) localname, 0) == 0) {
- nodep = (xmlNodePtr) xmlNewDocProp(docp, (xmlChar *) localname, NULL);
- if (nodep != NULL && uri_len > 0) {
- nsptr = xmlSearchNsByHref(nodep->doc, root, (xmlChar *) uri);
- if (nsptr == NULL) {
- nsptr = dom_get_ns(root, uri, &errorcode, prefix);
- }
- xmlSetNs(nodep, nsptr);
- }
- } else {
- errorcode = INVALID_CHARACTER_ERR;
- }
- }
- } else {
- php_error_docref(NULL, E_WARNING, "Document Missing Root Element");
- RETURN_FALSE;
- }
- xmlFree(localname);
- if (prefix != NULL) {
- xmlFree(prefix);
- }
- if (errorcode != 0) {
- if (nodep != NULL) {
- xmlFreeProp((xmlAttrPtr) nodep);
- }
- php_dom_throw_error(errorcode, dom_get_strict_error(intern->document));
- RETURN_FALSE;
- }
- if (nodep == NULL) {
- RETURN_FALSE;
- }
- DOM_RET_OBJ(nodep, &ret, intern);
- }
- /* }}} end dom_document_create_attribute_ns */
- /* {{{ proto DOMNodeList dom_document_get_elements_by_tag_name_ns(string namespaceURI, string localName)
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-getElBTNNS
- Since: DOM Level 2
- */
- PHP_FUNCTION(dom_document_get_elements_by_tag_name_ns)
- {
- zval *id;
- xmlDocPtr docp;
- size_t uri_len, name_len;
- dom_object *intern, *namednode;
- char *uri, *name;
- xmlChar *local, *nsuri;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Oss", &id, dom_document_class_entry, &uri, &uri_len, &name, &name_len) == FAILURE) {
- return;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- php_dom_create_interator(return_value, DOM_NODELIST);
- namednode = Z_DOMOBJ_P(return_value);
- local = xmlCharStrndup(name, name_len);
- nsuri = xmlCharStrndup(uri, uri_len);
- dom_namednode_iter(intern, 0, namednode, NULL, local, nsuri);
- }
- /* }}} end dom_document_get_elements_by_tag_name_ns */
- /* {{{ proto DOMElement dom_document_get_element_by_id(string elementId)
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-getElBId
- Since: DOM Level 2
- */
- PHP_FUNCTION(dom_document_get_element_by_id)
- {
- zval *id;
- xmlDocPtr docp;
- xmlAttrPtr attrp;
- int ret;
- size_t idname_len;
- dom_object *intern;
- char *idname;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &id, dom_document_class_entry, &idname, &idname_len) == FAILURE) {
- return;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- attrp = xmlGetID(docp, (xmlChar *) idname);
- if (attrp && attrp->parent) {
- DOM_RET_OBJ((xmlNodePtr) attrp->parent, &ret, intern);
- } else {
- RETVAL_NULL();
- }
- }
- /* }}} end dom_document_get_element_by_id */
- /* {{{ proto DOMNode dom_document_adopt_node(DOMNode source)
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-adoptNode
- Since: DOM Level 3
- */
- PHP_FUNCTION(dom_document_adopt_node)
- {
- DOM_NOT_IMPLEMENTED();
- }
- /* }}} end dom_document_adopt_node */
- /* {{{ proto void dom_document_normalize_document()
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-normalizeDocument
- Since: DOM Level 3
- */
- PHP_FUNCTION(dom_document_normalize_document)
- {
- zval *id;
- xmlDocPtr docp;
- dom_object *intern;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &id, dom_document_class_entry) == FAILURE) {
- return;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- dom_normalize((xmlNodePtr) docp);
- }
- /* }}} end dom_document_normalize_document */
- /* {{{ proto DOMNode dom_document_rename_node(node n, string namespaceURI, string qualifiedName)
- URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-renameNode
- Since: DOM Level 3
- */
- PHP_FUNCTION(dom_document_rename_node)
- {
- DOM_NOT_IMPLEMENTED();
- }
- /* }}} end dom_document_rename_node */
- /* {{{ proto DOMDocument::__construct([string version], [string encoding]); */
- PHP_METHOD(domdocument, __construct)
- {
- zval *id = getThis();
- xmlDoc *docp = NULL, *olddoc;
- dom_object *intern;
- char *encoding, *version = NULL;
- size_t encoding_len = 0, version_len = 0;
- int refcount;
- if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|ss", &version, &version_len, &encoding, &encoding_len) == FAILURE) {
- return;
- }
- docp = xmlNewDoc((xmlChar *) version);
- if (!docp) {
- php_dom_throw_error(INVALID_STATE_ERR, 1);
- RETURN_FALSE;
- }
- if (encoding_len > 0) {
- docp->encoding = (const xmlChar *) xmlStrdup((xmlChar *) encoding);
- }
- intern = Z_DOMOBJ_P(id);
- if (intern != NULL) {
- olddoc = (xmlDocPtr) dom_object_get_node(intern);
- if (olddoc != NULL) {
- php_libxml_decrement_node_ptr((php_libxml_node_object *) intern);
- refcount = php_libxml_decrement_doc_ref((php_libxml_node_object *)intern);
- if (refcount != 0) {
- olddoc->_private = NULL;
- }
- }
- intern->document = NULL;
- if (php_libxml_increment_doc_ref((php_libxml_node_object *)intern, docp) == -1) {
- RETURN_FALSE;
- }
- php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)docp, (void *)intern);
- }
- }
- /* }}} end DOMDocument::__construct */
- char *_dom_get_valid_file_path(char *source, char *resolved_path, int resolved_path_len ) /* {{{ */
- {
- xmlURI *uri;
- xmlChar *escsource;
- char *file_dest;
- int isFileUri = 0;
- uri = xmlCreateURI();
- escsource = xmlURIEscapeStr((xmlChar *) source, (xmlChar *) ":");
- xmlParseURIReference(uri, (char *) escsource);
- xmlFree(escsource);
- if (uri->scheme != NULL) {
- /* absolute file uris - libxml only supports localhost or empty host */
- #ifdef PHP_WIN32
- if (strncasecmp(source, "file://",7) == 0 && ':' == source[8]) {
- isFileUri = 1;
- source += 7;
- } else
- #endif
- if (strncasecmp(source, "file:///",8) == 0) {
- isFileUri = 1;
- #ifdef PHP_WIN32
- source += 8;
- #else
- source += 7;
- #endif
- } else if (strncasecmp(source, "file://localhost/",17) == 0) {
- isFileUri = 1;
- #ifdef PHP_WIN32
- source += 17;
- #else
- source += 16;
- #endif
- }
- }
- file_dest = source;
- if ((uri->scheme == NULL || isFileUri)) {
- /* XXX possible buffer overflow if VCWD_REALPATH does not know size of resolved_path */
- if (!VCWD_REALPATH(source, resolved_path) && !expand_filepath(source, resolved_path)) {
- xmlFreeURI(uri);
- return NULL;
- }
- file_dest = resolved_path;
- }
- xmlFreeURI(uri);
- return file_dest;
- }
- /* }}} */
- static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, size_t source_len, size_t options) /* {{{ */
- {
- xmlDocPtr ret;
- xmlParserCtxtPtr ctxt = NULL;
- dom_doc_propsptr doc_props;
- dom_object *intern;
- php_libxml_ref_obj *document = NULL;
- int validate, recover, resolve_externals, keep_blanks, substitute_ent;
- int resolved_path_len;
- int old_error_reporting = 0;
- char *directory=NULL, resolved_path[MAXPATHLEN];
- if (id != NULL) {
- intern = Z_DOMOBJ_P(id);
- document = intern->document;
- }
- doc_props = dom_get_doc_props(document);
- validate = doc_props->validateonparse;
- resolve_externals = doc_props->resolveexternals;
- keep_blanks = doc_props->preservewhitespace;
- substitute_ent = doc_props->substituteentities;
- recover = doc_props->recover;
- if (document == NULL) {
- efree(doc_props);
- }
- xmlInitParser();
- if (mode == DOM_LOAD_FILE) {
- char *file_dest;
- if (CHECK_NULL_PATH(source, source_len)) {
- return NULL;
- }
- file_dest = _dom_get_valid_file_path(source, resolved_path, MAXPATHLEN);
- if (file_dest) {
- ctxt = xmlCreateFileParserCtxt(file_dest);
- }
- } else {
- ctxt = xmlCreateMemoryParserCtxt(source, source_len);
- }
- if (ctxt == NULL) {
- return(NULL);
- }
- /* If loading from memory, we need to set the base directory for the document */
- if (mode != DOM_LOAD_FILE) {
- #if HAVE_GETCWD
- directory = VCWD_GETCWD(resolved_path, MAXPATHLEN);
- #elif HAVE_GETWD
- directory = VCWD_GETWD(resolved_path);
- #endif
- if (directory) {
- if(ctxt->directory != NULL) {
- xmlFree((char *) ctxt->directory);
- }
- resolved_path_len = strlen(resolved_path);
- if (resolved_path[resolved_path_len - 1] != DEFAULT_SLASH) {
- resolved_path[resolved_path_len] = DEFAULT_SLASH;
- resolved_path[++resolved_path_len] = '\0';
- }
- ctxt->directory = (char *) xmlCanonicPath((const xmlChar *) resolved_path);
- }
- }
- ctxt->vctxt.error = php_libxml_ctx_error;
- ctxt->vctxt.warning = php_libxml_ctx_warning;
- if (ctxt->sax != NULL) {
- ctxt->sax->error = php_libxml_ctx_error;
- ctxt->sax->warning = php_libxml_ctx_warning;
- }
- if (validate && ! (options & XML_PARSE_DTDVALID)) {
- options |= XML_PARSE_DTDVALID;
- }
- if (resolve_externals && ! (options & XML_PARSE_DTDATTR)) {
- options |= XML_PARSE_DTDATTR;
- }
- if (substitute_ent && ! (options & XML_PARSE_NOENT)) {
- options |= XML_PARSE_NOENT;
- }
- if (keep_blanks == 0 && ! (options & XML_PARSE_NOBLANKS)) {
- options |= XML_PARSE_NOBLANKS;
- }
- xmlCtxtUseOptions(ctxt, options);
- ctxt->recovery = recover;
- if (recover) {
- old_error_reporting = EG(error_reporting);
- EG(error_reporting) = old_error_reporting | E_WARNING;
- }
- xmlParseDocument(ctxt);
- if (ctxt->wellFormed || recover) {
- ret = ctxt->myDoc;
- if (ctxt->recovery) {
- EG(error_reporting) = old_error_reporting;
- }
- /* If loading from memory, set the base reference uri for the document */
- if (ret && ret->URL == NULL && ctxt->directory != NULL) {
- ret->URL = xmlStrdup((xmlChar *) ctxt->directory);
- }
- } else {
- ret = NULL;
- xmlFreeDoc(ctxt->myDoc);
- ctxt->myDoc = NULL;
- }
- xmlFreeParserCtxt(ctxt);
- return(ret);
- }
- /* }}} */
- /* {{{ static void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode) */
- static void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode) {
- zval *id;
- xmlDoc *docp = NULL, *newdoc;
- dom_doc_propsptr doc_prop;
- dom_object *intern;
- char *source;
- size_t source_len;
- int refcount, ret;
- zend_long options = 0;
- id = getThis();
- if (id != NULL && ! instanceof_function(Z_OBJCE_P(id), dom_document_class_entry)) {
- id = NULL;
- }
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &source, &source_len, &options) == FAILURE) {
- return;
- }
- if (!source_len) {
- php_error_docref(NULL, E_WARNING, "Empty string supplied as input");
- RETURN_FALSE;
- }
- if (ZEND_SIZE_T_INT_OVFL(source_len)) {
- php_error_docref(NULL, E_WARNING, "Input string is too long");
- RETURN_FALSE;
- }
- if (ZEND_LONG_EXCEEDS_INT(options)) {
- php_error_docref(NULL, E_WARNING, "Invalid options");
- RETURN_FALSE;
- }
- newdoc = dom_document_parser(id, mode, source, source_len, options);
- if (!newdoc)
- RETURN_FALSE;
- if (id != NULL) {
- intern = Z_DOMOBJ_P(id);
- if (intern != NULL) {
- docp = (xmlDocPtr) dom_object_get_node(intern);
- doc_prop = NULL;
- if (docp != NULL) {
- php_libxml_decrement_node_ptr((php_libxml_node_object *) intern);
- doc_prop = intern->document->doc_props;
- intern->document->doc_props = NULL;
- refcount = php_libxml_decrement_doc_ref((php_libxml_node_object *)intern);
- if (refcount != 0) {
- docp->_private = NULL;
- }
- }
- intern->document = NULL;
- if (php_libxml_increment_doc_ref((php_libxml_node_object *)intern, newdoc) == -1) {
- RETURN_FALSE;
- }
- intern->document->doc_props = doc_prop;
- }
- php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)newdoc, (void *)intern);
- RETURN_TRUE;
- } else {
- DOM_RET_OBJ((xmlNodePtr) newdoc, &ret, NULL);
- }
- }
- /* }}} end dom_parser_document */
- /* {{{ proto DOMNode dom_document_load(string source [, int options])
- URL: http://www.w3.org/TR/DOM-Level-3-LS/load-save.html#LS-DocumentLS-load
- Since: DOM Level 3
- */
- PHP_METHOD(domdocument, load)
- {
- dom_parse_document(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_FILE);
- }
- /* }}} end dom_document_load */
- /* {{{ proto DOMNode dom_document_loadxml(string source [, int options])
- URL: http://www.w3.org/TR/DOM-Level-3-LS/load-save.html#LS-DocumentLS-loadXML
- Since: DOM Level 3
- */
- PHP_METHOD(domdocument, loadXML)
- {
- dom_parse_document(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_STRING);
- }
- /* }}} end dom_document_loadxml */
- /* {{{ proto int dom_document_save(string file)
- Convenience method to save to file
- */
- PHP_FUNCTION(dom_document_save)
- {
- zval *id;
- xmlDoc *docp;
- size_t file_len = 0;
- int bytes, format, saveempty = 0;
- dom_object *intern;
- dom_doc_propsptr doc_props;
- char *file;
- zend_long options = 0;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Op|l", &id, dom_document_class_entry, &file, &file_len, &options) == FAILURE) {
- return;
- }
- if (file_len == 0) {
- php_error_docref(NULL, E_WARNING, "Invalid Filename");
- RETURN_FALSE;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- /* encoding handled by property on doc */
- doc_props = dom_get_doc_props(intern->document);
- format = doc_props->formatoutput;
- if (options & LIBXML_SAVE_NOEMPTYTAG) {
- saveempty = xmlSaveNoEmptyTags;
- xmlSaveNoEmptyTags = 1;
- }
- bytes = xmlSaveFormatFileEnc(file, docp, NULL, format);
- if (options & LIBXML_SAVE_NOEMPTYTAG) {
- xmlSaveNoEmptyTags = saveempty;
- }
- if (bytes == -1) {
- RETURN_FALSE;
- }
- RETURN_LONG(bytes);
- }
- /* }}} end dom_document_save */
- /* {{{ proto string dom_document_savexml([node n])
- URL: http://www.w3.org/TR/DOM-Level-3-LS/load-save.html#LS-DocumentLS-saveXML
- Since: DOM Level 3
- */
- PHP_FUNCTION(dom_document_savexml)
- {
- zval *id, *nodep = NULL;
- xmlDoc *docp;
- xmlNode *node;
- xmlBufferPtr buf;
- xmlChar *mem;
- dom_object *intern, *nodeobj;
- dom_doc_propsptr doc_props;
- int size, format, saveempty = 0;
- zend_long options = 0;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|O!l", &id, dom_document_class_entry, &nodep, dom_node_class_entry, &options) == FAILURE) {
- return;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- doc_props = dom_get_doc_props(intern->document);
- format = doc_props->formatoutput;
- if (nodep != NULL) {
- /* Dump contents of Node */
- DOM_GET_OBJ(node, nodep, xmlNodePtr, nodeobj);
- if (node->doc != docp) {
- php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(intern->document));
- RETURN_FALSE;
- }
- buf = xmlBufferCreate();
- if (!buf) {
- php_error_docref(NULL, E_WARNING, "Could not fetch buffer");
- RETURN_FALSE;
- }
- if (options & LIBXML_SAVE_NOEMPTYTAG) {
- saveempty = xmlSaveNoEmptyTags;
- xmlSaveNoEmptyTags = 1;
- }
- xmlNodeDump(buf, docp, node, 0, format);
- if (options & LIBXML_SAVE_NOEMPTYTAG) {
- xmlSaveNoEmptyTags = saveempty;
- }
- mem = (xmlChar*) xmlBufferContent(buf);
- if (!mem) {
- xmlBufferFree(buf);
- RETURN_FALSE;
- }
- RETVAL_STRING((char *) mem);
- xmlBufferFree(buf);
- } else {
- if (options & LIBXML_SAVE_NOEMPTYTAG) {
- saveempty = xmlSaveNoEmptyTags;
- xmlSaveNoEmptyTags = 1;
- }
- /* Encoding is handled from the encoding property set on the document */
- xmlDocDumpFormatMemory(docp, &mem, &size, format);
- if (options & LIBXML_SAVE_NOEMPTYTAG) {
- xmlSaveNoEmptyTags = saveempty;
- }
- if (!size || !mem) {
- RETURN_FALSE;
- }
- RETVAL_STRINGL((char *) mem, size);
- xmlFree(mem);
- }
- }
- /* }}} end dom_document_savexml */
- static xmlNodePtr php_dom_free_xinclude_node(xmlNodePtr cur) /* {{{ */
- {
- xmlNodePtr xincnode;
- xincnode = cur;
- cur = cur->next;
- xmlUnlinkNode(xincnode);
- php_libxml_node_free_resource(xincnode);
- return cur;
- }
- /* }}} */
- static void php_dom_remove_xinclude_nodes(xmlNodePtr cur) /* {{{ */
- {
- while(cur) {
- if (cur->type == XML_XINCLUDE_START) {
- cur = php_dom_free_xinclude_node(cur);
- /* XML_XINCLUDE_END node will be a sibling of XML_XINCLUDE_START */
- while(cur && cur->type != XML_XINCLUDE_END) {
- /* remove xinclude processing nodes from recursive xincludes */
- if (cur->type == XML_ELEMENT_NODE) {
- php_dom_remove_xinclude_nodes(cur->children);
- }
- cur = cur->next;
- }
- if (cur && cur->type == XML_XINCLUDE_END) {
- cur = php_dom_free_xinclude_node(cur);
- }
- } else {
- if (cur->type == XML_ELEMENT_NODE) {
- php_dom_remove_xinclude_nodes(cur->children);
- }
- cur = cur->next;
- }
- }
- }
- /* }}} */
- /* {{{ proto int dom_document_xinclude([int options])
- Substitutues xincludes in a DomDocument */
- PHP_FUNCTION(dom_document_xinclude)
- {
- zval *id;
- xmlDoc *docp;
- xmlNodePtr root;
- zend_long flags = 0;
- int err;
- dom_object *intern;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|l", &id, dom_document_class_entry, &flags) == FAILURE) {
- return;
- }
- if (ZEND_LONG_EXCEEDS_INT(flags)) {
- php_error_docref(NULL, E_WARNING, "Invalid flags");
- RETURN_FALSE;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- err = xmlXIncludeProcessFlags(docp, (int)flags);
- /* XML_XINCLUDE_START and XML_XINCLUDE_END nodes need to be removed as these
- are added via xmlXIncludeProcess to mark beginning and ending of xincluded document
- but are not wanted in resulting document - must be done even if err as it could fail after
- having processed some xincludes */
- root = (xmlNodePtr) docp->children;
- while(root && root->type != XML_ELEMENT_NODE && root->type != XML_XINCLUDE_START) {
- root = root->next;
- }
- if (root) {
- php_dom_remove_xinclude_nodes(root);
- }
- if (err) {
- RETVAL_LONG(err);
- } else {
- RETVAL_FALSE;
- }
- }
- /* }}} */
- /* {{{ proto bool dom_document_validate()
- Since: DOM extended
- */
- PHP_FUNCTION(dom_document_validate)
- {
- zval *id;
- xmlDoc *docp;
- dom_object *intern;
- xmlValidCtxt *cvp;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &id, dom_document_class_entry) == FAILURE) {
- return;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- cvp = xmlNewValidCtxt();
- cvp->userData = NULL;
- cvp->error = (xmlValidityErrorFunc) php_libxml_error_handler;
- cvp->warning = (xmlValidityErrorFunc) php_libxml_error_handler;
- if (xmlValidateDocument(cvp, docp)) {
- RETVAL_TRUE;
- } else {
- RETVAL_FALSE;
- }
- xmlFreeValidCtxt(cvp);
- }
- /* }}} */
- #if defined(LIBXML_SCHEMAS_ENABLED)
- static void _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
- {
- zval *id;
- xmlDoc *docp;
- dom_object *intern;
- char *source = NULL, *valid_file = NULL;
- size_t source_len = 0;
- int valid_opts = 0;
- zend_long flags = 0;
- xmlSchemaParserCtxtPtr parser;
- xmlSchemaPtr sptr;
- xmlSchemaValidCtxtPtr vptr;
- int is_valid;
- char resolved_path[MAXPATHLEN + 1];
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os|l", &id, dom_document_class_entry, &source, &source_len, &flags) == FAILURE) {
- return;
- }
- if (source_len == 0) {
- php_error_docref(NULL, E_WARNING, "Invalid Schema source");
- RETURN_FALSE;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- switch (type) {
- case DOM_LOAD_FILE:
- if (CHECK_NULL_PATH(source, source_len)) {
- php_error_docref(NULL, E_WARNING, "Invalid Schema file source");
- RETURN_FALSE;
- }
- valid_file = _dom_get_valid_file_path(source, resolved_path, MAXPATHLEN);
- if (!valid_file) {
- php_error_docref(NULL, E_WARNING, "Invalid Schema file source");
- RETURN_FALSE;
- }
- parser = xmlSchemaNewParserCtxt(valid_file);
- break;
- case DOM_LOAD_STRING:
- parser = xmlSchemaNewMemParserCtxt(source, source_len);
- /* If loading from memory, we need to set the base directory for the document
- but it is not apparent how to do that for schema's */
- break;
- default:
- return;
- }
- xmlSchemaSetParserErrors(parser,
- (xmlSchemaValidityErrorFunc) php_libxml_error_handler,
- (xmlSchemaValidityWarningFunc) php_libxml_error_handler,
- parser);
- sptr = xmlSchemaParse(parser);
- xmlSchemaFreeParserCtxt(parser);
- if (!sptr) {
- php_error_docref(NULL, E_WARNING, "Invalid Schema");
- RETURN_FALSE;
- }
- docp = (xmlDocPtr) dom_object_get_node(intern);
- vptr = xmlSchemaNewValidCtxt(sptr);
- if (!vptr) {
- xmlSchemaFree(sptr);
- zend_throw_error(NULL, "Invalid Schema Validation Context");
- RETURN_FALSE;
- }
- #if LIBXML_VERSION >= 20614
- if (flags & XML_SCHEMA_VAL_VC_I_CREATE) {
- valid_opts |= XML_SCHEMA_VAL_VC_I_CREATE;
- }
- #endif
- xmlSchemaSetValidOptions(vptr, valid_opts);
- xmlSchemaSetValidErrors(vptr, php_libxml_error_handler, php_libxml_error_handler, vptr);
- is_valid = xmlSchemaValidateDoc(vptr, docp);
- xmlSchemaFree(sptr);
- xmlSchemaFreeValidCtxt(vptr);
- if (is_valid == 0) {
- RETURN_TRUE;
- } else {
- RETURN_FALSE;
- }
- }
- /* }}} */
- /* {{{ proto bool dom_document_schema_validate_file(string filename, int flags); */
- PHP_FUNCTION(dom_document_schema_validate_file)
- {
- _dom_document_schema_validate(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_FILE);
- }
- /* }}} end dom_document_schema_validate_file */
- /* {{{ proto bool dom_document_schema_validate(string source, int flags); */
- PHP_FUNCTION(dom_document_schema_validate_xml)
- {
- _dom_document_schema_validate(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_STRING);
- }
- /* }}} end dom_document_schema_validate */
- static void _dom_document_relaxNG_validate(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
- {
- zval *id;
- xmlDoc *docp;
- dom_object *intern;
- char *source = NULL, *valid_file = NULL;
- size_t source_len = 0;
- xmlRelaxNGParserCtxtPtr parser;
- xmlRelaxNGPtr sptr;
- xmlRelaxNGValidCtxtPtr vptr;
- int is_valid;
- char resolved_path[MAXPATHLEN + 1];
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &id, dom_document_class_entry, &source, &source_len) == FAILURE) {
- return;
- }
- if (source_len == 0) {
- php_error_docref(NULL, E_WARNING, "Invalid Schema source");
- RETURN_FALSE;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- switch (type) {
- case DOM_LOAD_FILE:
- if (CHECK_NULL_PATH(source, source_len)) {
- php_error_docref(NULL, E_WARNING, "Invalid RelaxNG file source");
- RETURN_FALSE;
- }
- valid_file = _dom_get_valid_file_path(source, resolved_path, MAXPATHLEN);
- if (!valid_file) {
- php_error_docref(NULL, E_WARNING, "Invalid RelaxNG file source");
- RETURN_FALSE;
- }
- parser = xmlRelaxNGNewParserCtxt(valid_file);
- break;
- case DOM_LOAD_STRING:
- parser = xmlRelaxNGNewMemParserCtxt(source, source_len);
- /* If loading from memory, we need to set the base directory for the document
- but it is not apparent how to do that for schema's */
- break;
- default:
- return;
- }
- xmlRelaxNGSetParserErrors(parser,
- (xmlRelaxNGValidityErrorFunc) php_libxml_error_handler,
- (xmlRelaxNGValidityWarningFunc) php_libxml_error_handler,
- parser);
- sptr = xmlRelaxNGParse(parser);
- xmlRelaxNGFreeParserCtxt(parser);
- if (!sptr) {
- php_error_docref(NULL, E_WARNING, "Invalid RelaxNG");
- RETURN_FALSE;
- }
- docp = (xmlDocPtr) dom_object_get_node(intern);
- vptr = xmlRelaxNGNewValidCtxt(sptr);
- if (!vptr) {
- xmlRelaxNGFree(sptr);
- zend_throw_error(NULL, "Invalid RelaxNG Validation Context");
- RETURN_FALSE;
- }
- xmlRelaxNGSetValidErrors(vptr, php_libxml_error_handler, php_libxml_error_handler, vptr);
- is_valid = xmlRelaxNGValidateDoc(vptr, docp);
- xmlRelaxNGFree(sptr);
- xmlRelaxNGFreeValidCtxt(vptr);
- if (is_valid == 0) {
- RETURN_TRUE;
- } else {
- RETURN_FALSE;
- }
- }
- /* }}} */
- /* {{{ proto bool dom_document_relaxNG_validate_file(string filename); */
- PHP_FUNCTION(dom_document_relaxNG_validate_file)
- {
- _dom_document_relaxNG_validate(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_FILE);
- }
- /* }}} end dom_document_relaxNG_validate_file */
- /* {{{ proto bool dom_document_relaxNG_validate_xml(string source); */
- PHP_FUNCTION(dom_document_relaxNG_validate_xml)
- {
- _dom_document_relaxNG_validate(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_STRING);
- }
- /* }}} end dom_document_relaxNG_validate_xml */
- #endif
- #if defined(LIBXML_HTML_ENABLED)
- static void dom_load_html(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */
- {
- zval *id;
- xmlDoc *docp = NULL, *newdoc;
- dom_object *intern;
- dom_doc_propsptr doc_prop;
- char *source;
- size_t source_len;
- int refcount, ret;
- zend_long options = 0;
- htmlParserCtxtPtr ctxt;
- id = getThis();
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &source, &source_len, &options) == FAILURE) {
- return;
- }
- if (!source_len) {
- php_error_docref(NULL, E_WARNING, "Empty string supplied as input");
- RETURN_FALSE;
- }
- if (ZEND_LONG_EXCEEDS_INT(options)) {
- php_error_docref(NULL, E_WARNING, "Invalid options");
- RETURN_FALSE;
- }
- if (mode == DOM_LOAD_FILE) {
- if (CHECK_NULL_PATH(source, source_len)) {
- php_error_docref(NULL, E_WARNING, "Invalid file source");
- RETURN_FALSE;
- }
- ctxt = htmlCreateFileParserCtxt(source, NULL);
- } else {
- if (ZEND_SIZE_T_INT_OVFL(source_len)) {
- php_error_docref(NULL, E_WARNING, "Input string is too long");
- RETURN_FALSE;
- }
- ctxt = htmlCreateMemoryParserCtxt(source, (int)source_len);
- }
- if (!ctxt) {
- RETURN_FALSE;
- }
- ctxt->vctxt.error = php_libxml_ctx_error;
- ctxt->vctxt.warning = php_libxml_ctx_warning;
- if (ctxt->sax != NULL) {
- ctxt->sax->error = php_libxml_ctx_error;
- ctxt->sax->warning = php_libxml_ctx_warning;
- }
- if (options) {
- htmlCtxtUseOptions(ctxt, (int)options);
- }
- htmlParseDocument(ctxt);
- newdoc = ctxt->myDoc;
- htmlFreeParserCtxt(ctxt);
- if (!newdoc)
- RETURN_FALSE;
- if (id != NULL && instanceof_function(Z_OBJCE_P(id), dom_document_class_entry)) {
- intern = Z_DOMOBJ_P(id);
- if (intern != NULL) {
- docp = (xmlDocPtr) dom_object_get_node(intern);
- doc_prop = NULL;
- if (docp != NULL) {
- php_libxml_decrement_node_ptr((php_libxml_node_object *) intern);
- doc_prop = intern->document->doc_props;
- intern->document->doc_props = NULL;
- refcount = php_libxml_decrement_doc_ref((php_libxml_node_object *)intern);
- if (refcount != 0) {
- docp->_private = NULL;
- }
- }
- intern->document = NULL;
- if (php_libxml_increment_doc_ref((php_libxml_node_object *)intern, newdoc) == -1) {
- RETURN_FALSE;
- }
- intern->document->doc_props = doc_prop;
- }
- php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)newdoc, (void *)intern);
- RETURN_TRUE;
- } else {
- DOM_RET_OBJ((xmlNodePtr) newdoc, &ret, NULL);
- }
- }
- /* }}} */
- /* {{{ proto DOMNode dom_document_load_html_file(string source)
- Since: DOM extended
- */
- PHP_METHOD(domdocument, loadHTMLFile)
- {
- dom_load_html(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_FILE);
- }
- /* }}} end dom_document_load_html_file */
- /* {{{ proto DOMNode dom_document_load_html(string source)
- Since: DOM extended
- */
- PHP_METHOD(domdocument, loadHTML)
- {
- dom_load_html(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_STRING);
- }
- /* }}} end dom_document_load_html */
- /* {{{ proto int dom_document_save_html_file(string file)
- Convenience method to save to file as html
- */
- PHP_FUNCTION(dom_document_save_html_file)
- {
- zval *id;
- xmlDoc *docp;
- size_t file_len;
- int bytes, format;
- dom_object *intern;
- dom_doc_propsptr doc_props;
- char *file;
- const char *encoding;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Op", &id, dom_document_class_entry, &file, &file_len) == FAILURE) {
- return;
- }
- if (file_len == 0) {
- php_error_docref(NULL, E_WARNING, "Invalid Filename");
- RETURN_FALSE;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- encoding = (const char *) htmlGetMetaEncoding(docp);
- doc_props = dom_get_doc_props(intern->document);
- format = doc_props->formatoutput;
- bytes = htmlSaveFileFormat(file, docp, encoding, format);
- if (bytes == -1) {
- RETURN_FALSE;
- }
- RETURN_LONG(bytes);
- }
- /* }}} end dom_document_save_html_file */
- /* {{{ proto string dom_document_save_html()
- Convenience method to output as html
- */
- PHP_FUNCTION(dom_document_save_html)
- {
- zval *id, *nodep = NULL;
- xmlDoc *docp;
- xmlNode *node;
- xmlOutputBufferPtr outBuf;
- xmlBufferPtr buf;
- dom_object *intern, *nodeobj;
- xmlChar *mem = NULL;
- int format;
- dom_doc_propsptr doc_props;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(),
- "O|O!", &id, dom_document_class_entry, &nodep, dom_node_class_entry)
- == FAILURE) {
- return;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- doc_props = dom_get_doc_props(intern->document);
- format = doc_props->formatoutput;
- if (nodep != NULL) {
- /* Dump contents of Node */
- DOM_GET_OBJ(node, nodep, xmlNodePtr, nodeobj);
- if (node->doc != docp) {
- php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(intern->document));
- RETURN_FALSE;
- }
- buf = xmlBufferCreate();
- if (!buf) {
- php_error_docref(NULL, E_WARNING, "Could not fetch buffer");
- RETURN_FALSE;
- }
- outBuf = xmlOutputBufferCreateBuffer(buf, NULL);
- if (!outBuf) {
- xmlBufferFree(buf);
- php_error_docref(NULL, E_WARNING, "Could not fetch output buffer");
- RETURN_FALSE;
- }
- if (node->type == XML_DOCUMENT_FRAG_NODE) {
- for (node = node->children; node; node = node->next) {
- htmlNodeDumpFormatOutput(outBuf, docp, node, NULL, format);
- if (outBuf->error) {
- break;
- }
- }
- } else {
- htmlNodeDumpFormatOutput(outBuf, docp, node, NULL, format);
- }
- if (!outBuf->error) {
- xmlOutputBufferFlush(outBuf);
- mem = (xmlChar*) xmlBufferContent(buf);
- if (!mem) {
- RETVAL_FALSE;
- } else {
- int size = xmlBufferLength(buf);
- RETVAL_STRINGL((const char*) mem, size);
- }
- } else {
- php_error_docref(NULL, E_WARNING, "Error dumping HTML node");
- RETVAL_FALSE;
- }
- xmlOutputBufferClose(outBuf);
- xmlBufferFree(buf);
- } else {
- int size = 0;
- #if LIBXML_VERSION >= 20623
- htmlDocDumpMemoryFormat(docp, &mem, &size, format);
- #else
- htmlDocDumpMemory(docp, &mem, &size);
- #endif
- if (!size || !mem) {
- RETVAL_FALSE;
- } else {
- RETVAL_STRINGL((const char*) mem, size);
- }
- if (mem)
- xmlFree(mem);
- }
- }
- /* }}} end dom_document_save_html */
- #endif /* defined(LIBXML_HTML_ENABLED) */
- /* {{{ proto bool DOMDocument::registerNodeClass(string baseclass, string extendedclass)
- Register extended class used to create base node type */
- PHP_METHOD(domdocument, registerNodeClass)
- {
- zval *id;
- xmlDoc *docp;
- zend_class_entry *basece = dom_node_class_entry, *ce = NULL;
- dom_object *intern;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "OCC!", &id, dom_document_class_entry, &basece, &ce) == FAILURE) {
- return;
- }
- if (ce == NULL || instanceof_function(ce, basece)) {
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- dom_set_doc_classmap(intern->document, basece, ce);
- RETURN_TRUE;
- }
- zend_throw_error(NULL, "Class %s is not derived from %s.", ZSTR_VAL(ce->name), ZSTR_VAL(basece->name));
- RETURN_FALSE;
- }
- /* }}} */
- #endif /* HAVE_LIBXML && HAVE_DOM */
- /*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: noet sw=4 ts=4 fdm=marker
- * vim<600: noet sw=4 ts=4
- */
|