diff options
author | Daniel Veillard <veillard@redhat.com> | 2012-08-14 11:01:07 +0800 |
---|---|---|
committer | Daniel Veillard <veillard@redhat.com> | 2012-08-14 11:01:07 +0800 |
commit | 97fa5b3c8f3fe6ff79123ab43ed6b846fd1dd6dd (patch) | |
tree | 164ae64c5d4fcdad50491f058aa8e68e853996b6 /xmlreader.c | |
parent | aabc08477cf7b5110bf4594edccfcb8d4611cfde (diff) | |
download | android_external_libxml2-97fa5b3c8f3fe6ff79123ab43ed6b846fd1dd6dd.tar.gz android_external_libxml2-97fa5b3c8f3fe6ff79123ab43ed6b846fd1dd6dd.tar.bz2 android_external_libxml2-97fa5b3c8f3fe6ff79123ab43ed6b846fd1dd6dd.zip |
Fix file and line report for XSD SAX and reader streaming validation
Things now work correctly at the xmllint level:
thinkpad:~/XML -> xmllint --sax --noout --schema test_schema.xsd
test_xml.xml
test_xml.xml:72721: Schemas validity error : Element 'level1': Missing
child element(s). Expected is ( level2 ).
test_xml.xml fails to validate
thinkpad:~/XML -> xmllint --stream --schema test_schema.xsd test_xml.xml
test_xml.xml:72721: Schemas validity error : Element 'level1': Missing
child element(s). Expected is ( level2 ).
test_xml.xml fails to validate
thinkpad:~/XML ->
* error.c: fix a corner case of not reporting lines when we should
* include/libxml/xmlschemas.h doc/symbols.xml: had to add new entry
points to set the filename on a validation context and a locator
callback used to fetch the line and file from the context
* xmlschemas.c: add the new entry points xmlSchemaValidateSetFilename()
and xmlSchemaValidateSetLocator(), plus make sure the error reporting
routine gets the information if available. Add a locator for SAX.
* xmlreader.c: add and plug a locator for readers.
Diffstat (limited to 'xmlreader.c')
-rw-r--r-- | xmlreader.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/xmlreader.c b/xmlreader.c index f9c7fa17..c6ca46eb 100644 --- a/xmlreader.c +++ b/xmlreader.c @@ -4155,6 +4155,60 @@ xmlTextReaderRelaxNGSetSchema(xmlTextReaderPtr reader, xmlRelaxNGPtr schema) { } /** + * xmlTextReaderLocator: + * @ctx: the xmlTextReaderPtr used + * @file: returned file information + * @line: returned line information + * + * Internal locator function for the readers + * + * Returns 0 in case the Schema validation could be (des)activated and + * -1 in case of error. + */ +static int +xmlTextReaderLocator(void *ctx, const char **file, unsigned long *line) { + xmlTextReaderPtr reader; + + if ((ctx == NULL) || ((file == NULL) && (line == NULL))) + return(-1); + + if (file != NULL) + *file = NULL; + if (line != NULL) + *line = 0; + + reader = (xmlTextReaderPtr) ctx; + if ((reader->ctxt != NULL) && (reader->ctxt->input != NULL)) { + if (file != NULL) + *file = reader->ctxt->input->filename; + if (line != NULL) + *line = reader->ctxt->input->line; + return(0); + } + if (reader->node != NULL) { + long res; + int ret = 0; + + if (line != NULL) { + res = xmlGetLineNo(reader->node); + if (res > 0) + *line = (unsigned long) res; + else + ret = -1; + } + if (file != NULL) { + xmlDocPtr doc = reader->node->doc; + if ((doc != NULL) && (doc->URL != NULL)) + *file = (const char *) doc->URL; + else + ret = -1; + } + return(ret); + } + return(-1); +} + +/** * xmlTextReaderSetSchema: * @reader: the xmlTextReaderPtr used * @schema: a precompiled Schema schema @@ -4221,6 +4275,10 @@ xmlTextReaderSetSchema(xmlTextReaderPtr reader, xmlSchemaPtr schema) { reader->xsdValidCtxt = NULL; return(-1); } + xmlSchemaValidateSetLocator(reader->xsdValidCtxt, + xmlTextReaderLocator, + (void *) reader); + if (reader->errorFunc != NULL) { xmlSchemaSetValidErrors(reader->xsdValidCtxt, xmlTextReaderValidityErrorRelay, @@ -4435,6 +4493,9 @@ xmlTextReaderSchemaValidateInternal(xmlTextReaderPtr reader, return(-1); } } + xmlSchemaValidateSetLocator(reader->xsdValidCtxt, + xmlTextReaderLocator, + (void *) reader); /* * Redirect the validation context's error channels to use * the reader channels. |