bool XMLReader::set_relaxng_schema(String source, int type) { SYNC_VM_REGS_SCOPED(); if (source.empty()) { raise_warning("Schema data source is required"); return false; } if (m_ptr) { int ret = -1; xmlRelaxNGPtr schema = nullptr; if (!source.empty()) { schema = _xmlreader_get_relaxNG(source, type, nullptr, nullptr); if (schema) { ret = xmlTextReaderRelaxNGSetSchema(m_ptr, schema); } } else { ret = xmlTextReaderRelaxNGSetSchema(m_ptr, nullptr); } if (ret == 0) { if (m_schema) { xmlRelaxNGFree((xmlRelaxNGPtr) m_schema); } m_schema = schema; return true; } } raise_warning("Unable to set schema. This must be set prior to reading or schema contains errors."); return false; }
/* {{{ php_xmlreader_set_relaxng_schema */ static void php_xmlreader_set_relaxng_schema(INTERNAL_FUNCTION_PARAMETERS, int type) { #ifdef LIBXML_SCHEMAS_ENABLED zval *id; size_t source_len = 0; int retval = -1; xmlreader_object *intern; xmlRelaxNGPtr schema = NULL; char *source; if (zend_parse_parameters(ZEND_NUM_ARGS(), "p!", &source, &source_len) == FAILURE) { return; } if (source != NULL && !source_len) { php_error_docref(NULL, E_WARNING, "Schema data source is required"); RETURN_FALSE; } id = getThis(); intern = Z_XMLREADER_P(id); if (intern && intern->ptr) { if (source) { schema = _xmlreader_get_relaxNG(source, source_len, type, NULL, NULL); if (schema) { retval = xmlTextReaderRelaxNGSetSchema(intern->ptr, schema); } } else { /* unset the associated relaxNG context and schema if one exists */ retval = xmlTextReaderRelaxNGSetSchema(intern->ptr, NULL); } if (retval == 0) { if (intern->schema) { xmlRelaxNGFree((xmlRelaxNGPtr) intern->schema); } intern->schema = schema; RETURN_TRUE; } } php_error_docref(NULL, E_WARNING, "Unable to set schema. This must be set prior to reading or schema contains errors."); RETURN_FALSE; #else php_error_docref(NULL, E_WARNING, "No Schema support built into libxml."); RETURN_FALSE; #endif }