Skip to content

Commit

Permalink
Add schema default/fixed value support
Browse files Browse the repository at this point in the history
Added support for adding fixed/default values during XSD validation
  • Loading branch information
DaveRandom committed Apr 11, 2013
1 parent a5cfe57 commit d7b05a1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 10 additions & 4 deletions ext/dom/document.c
Expand Up @@ -1973,14 +1973,15 @@ static void _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type
xmlDoc *docp;
dom_object *intern;
char *source = NULL, *valid_file = NULL;
int source_len = 0;
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(), "Op", &id, dom_document_class_entry, &source, &source_len) == FAILURE) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Op|l", &id, dom_document_class_entry, &source, &source_len, &flags) == FAILURE) {
return;
}

Expand Down Expand Up @@ -2029,6 +2030,11 @@ static void _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type
RETURN_FALSE;
}

if (flags & XML_SCHEMA_VAL_VC_I_CREATE) {
valid_opts |= XML_SCHEMA_VAL_VC_I_CREATE;
}

xmlSchemaSetValidOptions(vptr, valid_opts);
xmlSchemaSetValidErrors(vptr, php_libxml_error_handler, php_libxml_error_handler, vptr);
is_valid = xmlSchemaValidateDoc(vptr, docp);
xmlSchemaFree(sptr);
Expand All @@ -2042,14 +2048,14 @@ static void _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type
}
/* }}} */

/* {{{ proto boolean dom_document_schema_validate_file(string filename); */
/* {{{ 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); */
/* {{{ 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);
Expand Down
6 changes: 6 additions & 0 deletions ext/libxml/libxml.c
Expand Up @@ -44,6 +44,7 @@
#include <libxml/xmlsave.h>
#ifdef LIBXML_SCHEMAS_ENABLED
#include <libxml/relaxng.h>
#include <libxml/xmlschemas.h>
#endif

#include "php_libxml.h"
Expand Down Expand Up @@ -798,6 +799,11 @@ static PHP_MINIT_FUNCTION(libxml)
#endif
REGISTER_LONG_CONSTANT("LIBXML_NOEMPTYTAG", LIBXML_SAVE_NOEMPTYTAG, CONST_CS | CONST_PERSISTENT);

/* Schema validation options */
#if defined(LIBXML_SCHEMAS_ENABLED) && LIBXML_VERSION >= 20614
REGISTER_LONG_CONSTANT("LIBXML_SCHEMA_CREATE", XML_SCHEMA_VAL_VC_I_CREATE, CONST_CS | CONST_PERSISTENT);
#endif

/* Additional constants for use with loading html */
#if LIBXML_VERSION >= 20707
REGISTER_LONG_CONSTANT("LIBXML_HTML_NOIMPLIED", HTML_PARSE_NOIMPLIED, CONST_CS | CONST_PERSISTENT);
Expand Down

0 comments on commit d7b05a1

Please sign in to comment.