123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406 |
- /*
- +----------------------------------------------------------------------+
- | PHP Version 5 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2016 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> |
- +----------------------------------------------------------------------+
- */
- /* $Id$ */
- #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_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: http://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 TSRMLS_DC)
- {
- xmlDoc *docp;
- xmlDtdPtr dtdptr;
- int ret;
- docp = (xmlDocPtr) dom_object_get_node(obj);
- if (docp == NULL) {
- php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
- return FAILURE;
- }
- ALLOC_ZVAL(*retval);
- dtdptr = xmlGetIntSubset(docp);
- if (!dtdptr) {
- ZVAL_NULL(*retval);
- return SUCCESS;
- }
- if (NULL == (*retval = php_dom_create_object((xmlNodePtr) dtdptr, &ret, *retval, obj TSRMLS_CC))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
- return FAILURE;
- }
- 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 TSRMLS_DC)
- {
- ALLOC_ZVAL(*retval);
- php_dom_create_implementation(retval TSRMLS_CC);
- 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 TSRMLS_DC)
- {
- xmlDoc *docp;
- xmlNode *root;
- int ret;
- docp = (xmlDocPtr) dom_object_get_node(obj);
- if (docp == NULL) {
- php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
- return FAILURE;
- }
- ALLOC_ZVAL(*retval);
- root = xmlDocGetRootElement(docp);
- if (!root) {
- ZVAL_NULL(*retval);
- return SUCCESS;
- }
- if (NULL == (*retval = php_dom_create_object(root, &ret, *retval, obj TSRMLS_CC))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
- return FAILURE;
- }
- 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 TSRMLS_DC)
- {
- xmlDoc *docp;
- char *encoding;
- docp = (xmlDocPtr) dom_object_get_node(obj);
- if (docp == NULL) {
- php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
- return FAILURE;
- }
- encoding = (char *) docp->encoding;
- ALLOC_ZVAL(*retval);
- if (encoding != NULL) {
- ZVAL_STRING(*retval, encoding, 1);
- } else {
- ZVAL_NULL(*retval);
- }
- return SUCCESS;
- }
- int dom_document_encoding_write(dom_object *obj, zval *newval TSRMLS_DC)
- {
- zval value_copy;
- xmlDoc *docp;
- xmlCharEncodingHandlerPtr handler;
- docp = (xmlDocPtr) dom_object_get_node(obj);
- if (docp == NULL) {
- php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
- return FAILURE;
- }
- convert_to_string_copy(newval, value_copy);
- handler = xmlFindCharEncodingHandler(Z_STRVAL_P(newval));
- if (handler != NULL) {
- xmlCharEncCloseFunc(handler);
- if (docp->encoding != NULL) {
- xmlFree((xmlChar *)docp->encoding);
- }
- docp->encoding = xmlStrdup((const xmlChar *) Z_STRVAL_P(newval));
- } else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Document Encoding");
- }
- if (newval == &value_copy) {
- zval_dtor(newval);
- }
- 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 TSRMLS_DC)
- {
- xmlDoc *docp;
- int standalone;
- docp = (xmlDocPtr) dom_object_get_node(obj);
- if (docp == NULL) {
- php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
- return FAILURE;
- }
- ALLOC_ZVAL(*retval);
- standalone = docp->standalone;
- ZVAL_BOOL(*retval, standalone);
- return SUCCESS;
- }
- int dom_document_standalone_write(dom_object *obj, zval *newval TSRMLS_DC)
- {
- zval value_copy;
- xmlDoc *docp;
- int standalone;
- docp = (xmlDocPtr) dom_object_get_node(obj);
- if (docp == NULL) {
- php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
- return FAILURE;
- }
- convert_to_long_copy(newval, value_copy);
- standalone = Z_LVAL_P(newval);
- if (standalone > 0) {
- docp->standalone = 1;
- }
- else if (standalone < 0) {
- docp->standalone = -1;
- }
- else {
- docp->standalone = 0;
- }
- if (newval == &value_copy) {
- zval_dtor(newval);
- }
- 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 TSRMLS_DC)
- {
- xmlDoc *docp;
- char *version;
- docp = (xmlDocPtr) dom_object_get_node(obj);
- if (docp == NULL) {
- php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
- return FAILURE;
- }
- version = (char *) docp->version;
- ALLOC_ZVAL(*retval);
- if (version != NULL) {
- ZVAL_STRING(*retval, version, 1);
- } else {
- ZVAL_NULL(*retval);
- }
- return SUCCESS;
- }
- int dom_document_version_write(dom_object *obj, zval *newval TSRMLS_DC)
- {
- zval value_copy;
- xmlDoc *docp;
- docp = (xmlDocPtr) dom_object_get_node(obj);
- if (docp == NULL) {
- php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
- return FAILURE;
- }
- if (docp->version != NULL) {
- xmlFree((xmlChar *) docp->version );
- }
- convert_to_string_copy(newval, value_copy);
- docp->version = xmlStrdup((const xmlChar *) Z_STRVAL_P(newval));
- if (newval == &value_copy) {
- zval_dtor(newval);
- }
- 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 TSRMLS_DC)
- {
- dom_doc_propsptr doc_prop;
- ALLOC_ZVAL(*retval);
- if (obj->document) {
- 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 TSRMLS_DC)
- {
- zval value_copy;
- dom_doc_propsptr doc_prop;
- convert_to_boolean_copy(newval, value_copy);
- if (obj->document) {
- doc_prop = dom_get_doc_props(obj->document);
- doc_prop->stricterror = Z_LVAL_P(newval);
- }
- if (newval == &value_copy) {
- zval_dtor(newval);
- }
- return SUCCESS;
- }
- /* }}} */
- /* {{{ formatOutput boolean
- readonly=no
- */
- int dom_document_format_output_read(dom_object *obj, zval **retval TSRMLS_DC)
- {
- dom_doc_propsptr doc_prop;
- ALLOC_ZVAL(*retval);
- if (obj->document) {
- 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 TSRMLS_DC)
- {
- zval value_copy;
- dom_doc_propsptr doc_prop;
- convert_to_boolean_copy(newval, value_copy);
- if (obj->document) {
- doc_prop = dom_get_doc_props(obj->document);
- doc_prop->formatoutput = Z_LVAL_P(newval);
- }
- if (newval == &value_copy) {
- zval_dtor(newval);
- }
- return SUCCESS;
- }
- /* }}} */
- /* {{{ validateOnParse boolean
- readonly=no
- */
- int dom_document_validate_on_parse_read(dom_object *obj, zval **retval TSRMLS_DC)
- {
- dom_doc_propsptr doc_prop;
- ALLOC_ZVAL(*retval);
- if (obj->document) {
- 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 TSRMLS_DC)
- {
- zval value_copy;
- dom_doc_propsptr doc_prop;
- convert_to_boolean_copy(newval, value_copy);
- if (obj->document) {
- doc_prop = dom_get_doc_props(obj->document);
- doc_prop->validateonparse = Z_LVAL_P(newval);
- }
- if (newval == &value_copy) {
- zval_dtor(newval);
- }
- return SUCCESS;
- }
- /* }}} */
- /* {{{ resolveExternals boolean
- readonly=no
- */
- int dom_document_resolve_externals_read(dom_object *obj, zval **retval TSRMLS_DC)
- {
- dom_doc_propsptr doc_prop;
- ALLOC_ZVAL(*retval);
- if (obj->document) {
- 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 TSRMLS_DC)
- {
- zval value_copy;
- dom_doc_propsptr doc_prop;
- convert_to_boolean_copy(newval, value_copy);
- if (obj->document) {
- doc_prop = dom_get_doc_props(obj->document);
- doc_prop->resolveexternals = Z_LVAL_P(newval);
- }
- if (newval == &value_copy) {
- zval_dtor(newval);
- }
- return SUCCESS;
- }
- /* }}} */
- /* {{{ preserveWhiteSpace boolean
- readonly=no
- */
- int dom_document_preserve_whitespace_read(dom_object *obj, zval **retval TSRMLS_DC)
- {
- dom_doc_propsptr doc_prop;
- ALLOC_ZVAL(*retval);
- if (obj->document) {
- 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 TSRMLS_DC)
- {
- zval value_copy;
- dom_doc_propsptr doc_prop;
- convert_to_boolean_copy(newval, value_copy);
- if (obj->document) {
- doc_prop = dom_get_doc_props(obj->document);
- doc_prop->preservewhitespace = Z_LVAL_P(newval);
- }
- if (newval == &value_copy) {
- zval_dtor(newval);
- }
- return SUCCESS;
- }
- /* }}} */
- /* {{{ recover boolean
- readonly=no
- */
- int dom_document_recover_read(dom_object *obj, zval **retval TSRMLS_DC)
- {
- dom_doc_propsptr doc_prop;
- ALLOC_ZVAL(*retval);
- if (obj->document) {
- 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 TSRMLS_DC)
- {
- zval value_copy;
- dom_doc_propsptr doc_prop;
- convert_to_boolean_copy(newval, value_copy);
- if (obj->document) {
- doc_prop = dom_get_doc_props(obj->document);
- doc_prop->recover = Z_LVAL_P(newval);
- }
- if (newval == &value_copy) {
- zval_dtor(newval);
- }
- return SUCCESS;
- }
- /* }}} */
- /* {{{ substituteEntities boolean
- readonly=no
- */
- int dom_document_substitue_entities_read(dom_object *obj, zval **retval TSRMLS_DC)
- {
- dom_doc_propsptr doc_prop;
- ALLOC_ZVAL(*retval);
- if (obj->document) {
- 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 TSRMLS_DC)
- {
- zval value_copy;
- dom_doc_propsptr doc_prop;
- convert_to_boolean_copy(newval, value_copy);
- if (obj->document) {
- doc_prop = dom_get_doc_props(obj->document);
- doc_prop->substituteentities = Z_LVAL_P(newval);
- }
- if (newval == &value_copy) {
- zval_dtor(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 TSRMLS_DC)
- {
- xmlDoc *docp;
- char *url;
- docp = (xmlDocPtr) dom_object_get_node(obj);
- if (docp == NULL) {
- php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
- return FAILURE;
- }
- ALLOC_ZVAL(*retval);
- url = (char *) docp->URL;
- if (url != NULL) {
- ZVAL_STRING(*retval, url, 1);
- } else {
- ZVAL_NULL(*retval);
- }
- return SUCCESS;
- }
- int dom_document_document_uri_write(dom_object *obj, zval *newval TSRMLS_DC)
- {
- zval value_copy;
- xmlDoc *docp;
- docp = (xmlDocPtr) dom_object_get_node(obj);
- if (docp == NULL) {
- php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
- return FAILURE;
- }
- if (docp->URL != NULL) {
- xmlFree((xmlChar *) docp->URL);
- }
- convert_to_string_copy(newval, value_copy);
- docp->URL = xmlStrdup((const xmlChar *) Z_STRVAL_P(newval));
- if (newval == &value_copy) {
- zval_dtor(newval);
- }
- 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 TSRMLS_DC)
- {
- ALLOC_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, name_len, value_len;
- char *name, *value = NULL;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, 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) TSRMLS_CC);
- RETURN_FALSE;
- }
- node = xmlNewDocNode(docp, NULL, name, 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() TSRMLS_CC, 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, value_len;
- dom_object *intern;
- char *value;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, 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, value_len;
- dom_object *intern;
- char *value;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, 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, value_len;
- dom_object *intern;
- char *value;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, 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, value_len, name_len = 0;
- dom_object *intern;
- char *name, *value = NULL;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, 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) TSRMLS_CC);
- 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, name_len;
- dom_object *intern;
- char *name;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, 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) TSRMLS_CC);
- 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, name_len;
- char *name;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, 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) TSRMLS_CC);
- RETURN_FALSE;
- }
- node = xmlNewReference(docp, 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;
- int name_len;
- dom_object *intern, *namednode;
- char *name;
- xmlChar *local;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, 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 TSRMLS_CC);
- namednode = (dom_object *)zend_objects_get_address(return_value TSRMLS_CC);
- local = xmlCharStrndup(name, name_len);
- dom_namednode_iter(intern, 0, namednode, NULL, local, NULL TSRMLS_CC);
- }
- /* }}} end dom_document_get_elements_by_tag_name */
- /* {{{ proto DOMNode dom_document_import_node(DOMNode importedNode, boolean 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;
- long recursive = 0;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO|l", &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 TSRMLS_CC, 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, 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() TSRMLS_CC, 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, localname, value);
- if (nodep != NULL && uri != NULL) {
- nsptr = xmlSearchNsByHref (nodep->doc, nodep, 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) TSRMLS_CC);
- 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, 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() TSRMLS_CC, 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, localname, NULL);
- if (nodep != NULL && uri_len > 0) {
- nsptr = xmlSearchNsByHref (nodep->doc, root, 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 TSRMLS_CC, 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) TSRMLS_CC);
- 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;
- int uri_len, name_len;
- dom_object *intern, *namednode;
- char *uri, *name;
- xmlChar *local, *nsuri;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, 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 TSRMLS_CC);
- namednode = (dom_object *)zend_objects_get_address(return_value TSRMLS_CC);
- local = xmlCharStrndup(name, name_len);
- nsuri = xmlCharStrndup(uri, uri_len);
- dom_namednode_iter(intern, 0, namednode, NULL, local, nsuri TSRMLS_CC);
- }
- /* }}} 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, idname_len;
- dom_object *intern;
- char *idname;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, 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() TSRMLS_CC, getThis(), "O", &id, dom_document_class_entry) == FAILURE) {
- return;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- dom_normalize((xmlNodePtr) docp TSRMLS_CC);
- }
- /* }}} 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 void DOMDocument::__construct([string version], [string encoding]); */
- PHP_METHOD(domdocument, __construct)
- {
- zval *id;
- xmlDoc *docp = NULL, *olddoc;
- dom_object *intern;
- char *encoding, *version = NULL;
- int encoding_len = 0, version_len = 0, refcount;
- zend_error_handling error_handling;
- zend_replace_error_handling(EH_THROW, dom_domexception_class_entry, &error_handling TSRMLS_CC);
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|ss", &id, dom_document_class_entry, &version, &version_len, &encoding, &encoding_len) == FAILURE) {
- zend_restore_error_handling(&error_handling TSRMLS_CC);
- return;
- }
- zend_restore_error_handling(&error_handling TSRMLS_CC);
- docp = xmlNewDoc(version);
- if (!docp) {
- php_dom_throw_error(INVALID_STATE_ERR, 1 TSRMLS_CC);
- RETURN_FALSE;
- }
- if (encoding_len > 0) {
- docp->encoding = (const xmlChar*)xmlStrdup(encoding);
- }
- intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
- if (intern != NULL) {
- olddoc = (xmlDocPtr) dom_object_get_node(intern);
- if (olddoc != NULL) {
- php_libxml_decrement_node_ptr((php_libxml_node_object *) intern TSRMLS_CC);
- refcount = php_libxml_decrement_doc_ref((php_libxml_node_object *)intern TSRMLS_CC);
- if (refcount != 0) {
- olddoc->_private = NULL;
- }
- }
- intern->document = NULL;
- if (php_libxml_increment_doc_ref((php_libxml_node_object *)intern, docp TSRMLS_CC) == -1) {
- RETURN_FALSE;
- }
- php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)docp, (void *)intern TSRMLS_CC);
- }
- }
- /* }}} end DOMDocument::__construct */
- char *_dom_get_valid_file_path(char *source, char *resolved_path, int resolved_path_len TSRMLS_DC) /* {{{ */
- {
- xmlURI *uri;
- xmlChar *escsource;
- char *file_dest;
- int isFileUri = 0;
- uri = xmlCreateURI();
- escsource = xmlURIEscapeStr(source, ":");
- xmlParseURIReference(uri, 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 TSRMLS_CC)) {
- xmlFreeURI(uri);
- return NULL;
- }
- file_dest = resolved_path;
- }
- xmlFreeURI(uri);
- return file_dest;
- }
- /* }}} */
- static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, int source_len, int options TSRMLS_DC) /* {{{ */
- {
- 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 = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
- 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 TSRMLS_CC);
- 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(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;
- int source_len, refcount, ret;
- long options = 0;
- id = getThis();
- if (id != NULL && ! instanceof_function(Z_OBJCE_P(id), dom_document_class_entry TSRMLS_CC)) {
- id = NULL;
- }
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &source, &source_len, &options) == FAILURE) {
- return;
- }
- if (!source_len) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty string supplied as input");
- RETURN_FALSE;
- }
- newdoc = dom_document_parser(id, mode, source, source_len, options TSRMLS_CC);
- if (!newdoc)
- RETURN_FALSE;
- if (id != NULL) {
- intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
- 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 TSRMLS_CC);
- doc_prop = intern->document->doc_props;
- intern->document->doc_props = NULL;
- refcount = php_libxml_decrement_doc_ref((php_libxml_node_object *)intern TSRMLS_CC);
- if (refcount != 0) {
- docp->_private = NULL;
- }
- }
- intern->document = NULL;
- if (php_libxml_increment_doc_ref((php_libxml_node_object *)intern, newdoc TSRMLS_CC) == -1) {
- RETURN_FALSE;
- }
- intern->document->doc_props = doc_prop;
- }
- php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)newdoc, (void *)intern TSRMLS_CC);
- 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;
- int file_len = 0, bytes, format, saveempty = 0;
- dom_object *intern;
- dom_doc_propsptr doc_props;
- char *file;
- long options = 0;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Op|l", &id, dom_document_class_entry, &file, &file_len, &options) == FAILURE) {
- return;
- }
- if (file_len == 0) {
- php_error_docref(NULL TSRMLS_CC, 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;
- long options = 0;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, 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) TSRMLS_CC);
- RETURN_FALSE;
- }
- buf = xmlBufferCreate();
- if (!buf) {
- php_error_docref(NULL TSRMLS_CC, 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(mem, 1);
- 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(mem, size, 1);
- xmlFree(mem);
- }
- }
- /* }}} end dom_document_savexml */
- static xmlNodePtr php_dom_free_xinclude_node(xmlNodePtr cur TSRMLS_DC) /* {{{ */
- {
- xmlNodePtr xincnode;
- xincnode = cur;
- cur = cur->next;
- xmlUnlinkNode(xincnode);
- php_libxml_node_free_resource(xincnode TSRMLS_CC);
- return cur;
- }
- /* }}} */
- static void php_dom_remove_xinclude_nodes(xmlNodePtr cur TSRMLS_DC) /* {{{ */
- {
- while(cur) {
- if (cur->type == XML_XINCLUDE_START) {
- cur = php_dom_free_xinclude_node(cur TSRMLS_CC);
- /* 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 TSRMLS_CC);
- }
- cur = cur->next;
- }
- if (cur && cur->type == XML_XINCLUDE_END) {
- cur = php_dom_free_xinclude_node(cur TSRMLS_CC);
- }
- } else {
- if (cur->type == XML_ELEMENT_NODE) {
- php_dom_remove_xinclude_nodes(cur->children TSRMLS_CC);
- }
- 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;
- long flags = 0;
- int err;
- dom_object *intern;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|l", &id, dom_document_class_entry, &flags) == FAILURE) {
- return;
- }
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- err = xmlXIncludeProcessFlags(docp, 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 TSRMLS_CC);
- }
- if (err) {
- RETVAL_LONG(err);
- } else {
- RETVAL_FALSE;
- }
- }
- /* }}} */
- /* {{{ proto boolean 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() TSRMLS_CC, 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;
- int source_len = 0, valid_opts = 0;
- 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() TSRMLS_CC, getThis(), "Os|l", &id, dom_document_class_entry, &source, &source_len, &flags) == FAILURE) {
- return;
- }
- if (source_len == 0) {
- php_error_docref(NULL TSRMLS_CC, 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 TSRMLS_CC, E_WARNING, "Invalid Schema file source");
- RETURN_FALSE;
- }
- valid_file = _dom_get_valid_file_path(source, resolved_path, MAXPATHLEN TSRMLS_CC);
- if (!valid_file) {
- php_error_docref(NULL TSRMLS_CC, 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 TSRMLS_CC, E_WARNING, "Invalid Schema");
- RETURN_FALSE;
- }
- docp = (xmlDocPtr) dom_object_get_node(intern);
- vptr = xmlSchemaNewValidCtxt(sptr);
- if (!vptr) {
- xmlSchemaFree(sptr);
- php_error(E_ERROR, "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 boolean 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 boolean 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;
- int 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() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &source, &source_len) == FAILURE) {
- return;
- }
- if (source_len == 0) {
- php_error_docref(NULL TSRMLS_CC, 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 TSRMLS_CC, E_WARNING, "Invalid RelaxNG file source");
- RETURN_FALSE;
- }
- valid_file = _dom_get_valid_file_path(source, resolved_path, MAXPATHLEN TSRMLS_CC);
- if (!valid_file) {
- php_error_docref(NULL TSRMLS_CC, 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 TSRMLS_CC, E_WARNING, "Invalid RelaxNG");
- RETURN_FALSE;
- }
- docp = (xmlDocPtr) dom_object_get_node(intern);
- vptr = xmlRelaxNGNewValidCtxt(sptr);
- if (!vptr) {
- xmlRelaxNGFree(sptr);
- php_error(E_ERROR, "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 boolean 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 boolean 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;
- int source_len, refcount, ret;
- long options = 0;
- htmlParserCtxtPtr ctxt;
- id = getThis();
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &source, &source_len, &options) == FAILURE) {
- return;
- }
- if (!source_len) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty string supplied as input");
- RETURN_FALSE;
- }
- if (mode == DOM_LOAD_FILE) {
- if (CHECK_NULL_PATH(source, source_len)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid file source");
- RETURN_FALSE;
- }
- ctxt = htmlCreateFileParserCtxt(source, NULL);
- } else {
- source_len = xmlStrlen(source);
- ctxt = htmlCreateMemoryParserCtxt(source, source_len);
- }
- if (!ctxt) {
- RETURN_FALSE;
- }
- if (options) {
- htmlCtxtUseOptions(ctxt, options);
- }
- 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;
- }
- htmlParseDocument(ctxt);
- newdoc = ctxt->myDoc;
- htmlFreeParserCtxt(ctxt);
- if (!newdoc)
- RETURN_FALSE;
- if (id != NULL && instanceof_function(Z_OBJCE_P(id), dom_document_class_entry TSRMLS_CC)) {
- intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
- 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 TSRMLS_CC);
- doc_prop = intern->document->doc_props;
- intern->document->doc_props = NULL;
- refcount = php_libxml_decrement_doc_ref((php_libxml_node_object *)intern TSRMLS_CC);
- if (refcount != 0) {
- docp->_private = NULL;
- }
- }
- intern->document = NULL;
- if (php_libxml_increment_doc_ref((php_libxml_node_object *)intern, newdoc TSRMLS_CC) == -1) {
- RETURN_FALSE;
- }
- intern->document->doc_props = doc_prop;
- }
- php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)newdoc, (void *)intern TSRMLS_CC);
- 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;
- int file_len, bytes, format;
- dom_object *intern;
- dom_doc_propsptr doc_props;
- char *file;
- const char *encoding;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Op", &id, dom_document_class_entry, &file, &file_len) == FAILURE) {
- return;
- }
- if (file_len == 0) {
- php_error_docref(NULL TSRMLS_CC, 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;
- xmlBufferPtr buf;
- dom_object *intern, *nodeobj;
- xmlChar *mem = NULL;
- int size = 0, format;
- dom_doc_propsptr doc_props;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, 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) TSRMLS_CC);
- RETURN_FALSE;
- }
- buf = xmlBufferCreate();
- if (!buf) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not fetch buffer");
- RETURN_FALSE;
- }
- if (node->type == XML_DOCUMENT_FRAG_NODE) {
- int one_size;
- for (node = node->children; node; node = node->next) {
- one_size = htmlNodeDump(buf, docp, node);
- if (one_size >= 0) {
- size += one_size;
- } else {
- size = -1;
- break;
- }
- }
- } else {
- size = htmlNodeDump(buf, docp, node);
- }
- if (size >= 0) {
- mem = (xmlChar*) xmlBufferContent(buf);
- if (!mem) {
- RETVAL_FALSE;
- } else {
- RETVAL_STRINGL((const char*) mem, size, 1);
- }
- } else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error dumping HTML node");
- RETVAL_FALSE;
- }
- xmlBufferFree(buf);
- } else {
- #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, 1);
- }
- if (mem)
- xmlFree(mem);
- }
- }
- /* }}} end dom_document_save_html */
- #endif /* defined(LIBXML_HTML_ENABLED) */
- /* {{{ proto boolean DOMDocument::registerNodeClass(string baseclass, string extendedclass);
- Register extended class used to create base node type */
- PHP_METHOD(domdocument, registerNodeClass)
- {
- zval *id;
- xmlDoc *docp;
- char *baseclass = NULL, *extendedclass = NULL;
- int baseclass_len = 0, extendedclass_len = 0;
- zend_class_entry *basece = NULL, *ce = NULL;
- dom_object *intern;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss!", &id, dom_document_class_entry, &baseclass, &baseclass_len, &extendedclass, &extendedclass_len) == FAILURE) {
- return;
- }
- if (baseclass_len) {
- zend_class_entry **pce;
- if (zend_lookup_class(baseclass, baseclass_len, &pce TSRMLS_CC) == FAILURE) {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Class %s does not exist", baseclass);
- return;
- }
- basece = *pce;
- }
- if (basece == NULL || ! instanceof_function(basece, dom_node_class_entry TSRMLS_CC)) {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Class %s is not derived from DOMNode.", baseclass);
- return;
- }
- if (extendedclass_len) {
- zend_class_entry **pce;
- if (zend_lookup_class(extendedclass, extendedclass_len, &pce TSRMLS_CC) == FAILURE) {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Class %s does not exist", extendedclass);
- }
- ce = *pce;
- }
- if (ce == NULL || instanceof_function(ce, basece TSRMLS_CC)) {
- DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
- if (dom_set_doc_classmap(intern->document, basece, ce TSRMLS_CC) == FAILURE) {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Class %s could not be registered.", extendedclass);
- }
- RETURN_TRUE;
- } else {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Class %s is not derived from %s.", extendedclass, baseclass);
- }
- 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
- */
|