Imported Upstream version 2.9.5_rc1
[platform/upstream/libxml2.git] / xmlschemas.c
index 2fb2151..1938d7e 100644 (file)
  *     but is done here due to performance. Move it to an other layer
  *     is schema construction via an API is implemented.
  */
+
+/* To avoid EBCDIC trouble when parsing on zOS */
+#if defined(__MVS__)
+#pragma convert("ISO8859-1")
+#endif
+
 #define IN_LIBXML
 #include "libxml.h"
 
 #endif
 
 #define UNBOUNDED (1 << 30)
-#define TODO                                                           \
+#define TODO                                                           \
     xmlGenericError(xmlGenericErrorContext,                            \
            "Unimplemented block at %s:%d\n",                           \
             __FILE__, __LINE__);
@@ -166,7 +172,7 @@ static const xmlChar *xmlNamespaceNs = (const xmlChar *)
 /*
 * Macros for attribute uses.
 */
-#define WXS_ATTRUSE_DECL(au) WXS_ATTR_CAST (WXS_ATTR_USE_CAST (au))->attrDecl
+#define WXS_ATTRUSE_DECL(au) (WXS_ATTR_USE_CAST (au))->attrDecl
 
 #define WXS_ATTRUSE_TYPEDEF(au) WXS_ATTR_TYPEDEF(WXS_ATTRUSE_DECL( WXS_ATTR_USE_CAST au))
 
@@ -363,6 +369,7 @@ typedef struct _xmlSchemaAbstractCtxt xmlSchemaAbstractCtxt;
 typedef xmlSchemaAbstractCtxt *xmlSchemaAbstractCtxtPtr;
 struct _xmlSchemaAbstractCtxt {
     int type; /* E.g. XML_SCHEMA_CTXT_VALIDATOR */
+    void *dummy; /* Fix alignment issues */
 };
 
 typedef struct _xmlSchemaBucket xmlSchemaBucket;
@@ -473,6 +480,7 @@ typedef struct _xmlSchemaBasicItem xmlSchemaBasicItem;
 typedef xmlSchemaBasicItem *xmlSchemaBasicItemPtr;
 struct _xmlSchemaBasicItem {
     xmlSchemaTypeType type;
+    void *dummy; /* Fix alignment issues */
 };
 
 /**
@@ -617,7 +625,7 @@ struct _xmlSchemaParserCtxt {
     xmlAutomataStatePtr end;
     xmlAutomataStatePtr state;
 
-    xmlDictPtr dict;           /* dictionnary for interned string names */
+    xmlDictPtr dict;           /* dictionary for interned string names */
     xmlSchemaTypePtr ctxtType; /* The current context simple/complex type */
     int options;
     xmlSchemaValidCtxtPtr vctxt;
@@ -975,6 +983,7 @@ struct _xmlSchemaValidCtxt {
     xmlSAXHandlerPtr sax;
     xmlParserCtxtPtr parserCtxt;
     void *user_data; /* TODO: What is this for? */
+    char *filename;
 
     int err;
     int nberrors;
@@ -1028,6 +1037,10 @@ struct _xmlSchemaValidCtxt {
     int hasKeyrefs;
     int createIDCNodeTables;
     int psviExposeIDCNodeTables;
+
+    /* Locator for error reporting in streaming mode */
+    xmlSchemaValidityLocatorFunc locFunc;
+    void *locCtxt;
 };
 
 /**
@@ -1043,9 +1056,9 @@ struct _xmlSchemaSubstGroup {
 };
 
 /************************************************************************
- *                                                                     *
- *                     Some predeclarations                            *
- *                                                                     *
+ *                                                                     *
+ *                     Some predeclarations                            *
+ *                                                                     *
  ************************************************************************/
 
 static int xmlSchemaParseInclude(xmlSchemaParserCtxtPtr ctxt,
@@ -1080,7 +1093,7 @@ xmlSchemaGetUnionSimpleTypeMemberTypes(xmlSchemaTypePtr type);
 static void
 xmlSchemaInternalErr(xmlSchemaAbstractCtxtPtr actxt,
                     const char *funcName,
-                    const char *message);
+                    const char *message) LIBXML_ATTR_FORMAT(3,0);
 static int
 xmlSchemaCheckCOSSTDerivedOK(xmlSchemaAbstractCtxtPtr ctxt,
                             xmlSchemaTypePtr type,
@@ -1098,7 +1111,7 @@ xmlSchemaParseAttributeGroupRef(xmlSchemaParserCtxtPtr pctxt,
 
 /************************************************************************
  *                                                                     *
- *                     Helper functions                                *
+ *                     Helper functions                                *
  *                                                                     *
  ************************************************************************/
 
@@ -1466,7 +1479,7 @@ xmlSchemaWildcardPCToString(int pc)
  * @retValue: the returned value
  * @ws: the whitespace type of the value
  *
- * Get a the cononical representation of the value.
+ * Get a the canonical representation of the value.
  * The caller has to free the returned retValue.
  *
  * Returns 0 if the value could be built and -1 in case of
@@ -1764,7 +1777,7 @@ xmlSchemaFormatItemForReport(xmlChar **buf,
     }
     FREE_AND_NULL(str)
 
-    return (*buf);
+    return (xmlEscapeFormatString(buf));
 }
 
 /**
@@ -1836,7 +1849,7 @@ xmlSchemaFormatFacetEnumSet(xmlSchemaAbstractCtxtPtr actxt,
 
 /************************************************************************
  *                                                                     *
- *                     Error functions                                 *
+ *                     Error functions                                 *
  *                                                                     *
  ************************************************************************/
 
@@ -1884,7 +1897,7 @@ xmlSchemaPErrMemory(xmlSchemaParserCtxtPtr ctxt,
  *
  * Handle a parser error
  */
-static void
+static void LIBXML_ATTR_FORMAT(4,0)
 xmlSchemaPErr(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error,
               const char *msg, const xmlChar * str1, const xmlChar * str2)
 {
@@ -1917,7 +1930,7 @@ xmlSchemaPErr(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error,
  *
  * Handle a parser error
  */
-static void
+static void LIBXML_ATTR_FORMAT(5,0)
 xmlSchemaPErr2(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,
                xmlNodePtr child, int error,
                const char *msg, const xmlChar * str1, const xmlChar * str2)
@@ -1946,7 +1959,7 @@ xmlSchemaPErr2(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,
  *
  * Handle a parser error
  */
-static void
+static void LIBXML_ATTR_FORMAT(7,0)
 xmlSchemaPErrExt(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error,
                const xmlChar * strData1, const xmlChar * strData2,
                const xmlChar * strData3, const char *msg, const xmlChar * str1,
@@ -1974,7 +1987,7 @@ xmlSchemaPErrExt(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error,
 
 /************************************************************************
  *                                                                     *
- *                     Allround error functions                        *
+ *                     Allround error functions                        *
  *                                                                     *
  ************************************************************************/
 
@@ -1997,7 +2010,7 @@ xmlSchemaVErrMemory(xmlSchemaValidCtxtPtr ctxt,
                      extra);
 }
 
-static void
+static void LIBXML_ATTR_FORMAT(2,0)
 xmlSchemaPSimpleInternalErr(xmlNodePtr node,
                            const char *msg, const xmlChar *str)
 {
@@ -2008,18 +2021,21 @@ xmlSchemaPSimpleInternalErr(xmlNodePtr node,
 #define WXS_ERROR_TYPE_ERROR 1
 #define WXS_ERROR_TYPE_WARNING 2
 /**
- * xmlSchemaErr3:
+ * xmlSchemaErr4Line:
  * @ctxt: the validation context
- * @node: the context node
+ * @errorLevel: the error level
  * @error: the error code
+ * @node: the context node
+ * @line: the line number
  * @msg: the error message
  * @str1: extra data
  * @str2: extra data
  * @str3: extra data
+ * @str4: extra data
  *
  * Handle a validation error
  */
-static void
+static void LIBXML_ATTR_FORMAT(6,0)
 xmlSchemaErr4Line(xmlSchemaAbstractCtxtPtr ctxt,
                  xmlErrorLevel errorLevel,
                  int error, xmlNodePtr node, int line, const char *msg,
@@ -2034,6 +2050,7 @@ xmlSchemaErr4Line(xmlSchemaAbstractCtxtPtr ctxt,
        if (ctxt->type == XML_SCHEMA_CTXT_VALIDATOR) {
            xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctxt;
            const char *file = NULL;
+           int col = 0;
            if (errorLevel != XML_ERR_WARNING) {
                vctxt->nberrors++;
                vctxt->err = error;
@@ -2062,6 +2079,7 @@ xmlSchemaErr4Line(xmlSchemaAbstractCtxtPtr ctxt,
                    (vctxt->parserCtxt->input != NULL)) {
                    file = vctxt->parserCtxt->input->filename;
                    line = vctxt->parserCtxt->input->line;
+                   col = vctxt->parserCtxt->input->col;
                }
            } else {
                /*
@@ -2078,11 +2096,25 @@ xmlSchemaErr4Line(xmlSchemaAbstractCtxtPtr ctxt,
                    (vctxt->parserCtxt->input != NULL))
                    file = vctxt->parserCtxt->input->filename;
            }
+           if (vctxt->locFunc != NULL) {
+               if ((file == NULL) || (line == 0)) {
+                   unsigned long l;
+                   const char *f;
+                   vctxt->locFunc(vctxt->locCtxt, &f, &l);
+                   if (file == NULL)
+                       file = f;
+                   if (line == 0)
+                       line = (int) l;
+               }
+           }
+           if ((file == NULL) && (vctxt->filename != NULL))
+               file = vctxt->filename;
+
            __xmlRaiseError(schannel, channel, data, ctxt,
                node, XML_FROM_SCHEMASV,
                error, errorLevel, file, line,
                (const char *) str1, (const char *) str2,
-               (const char *) str3, 0, 0, msg, str1, str2, str3, str4);
+               (const char *) str3, 0, col, msg, str1, str2, str3, str4);
 
        } else if (ctxt->type == XML_SCHEMA_CTXT_PARSER) {
            xmlSchemaParserCtxtPtr pctxt = (xmlSchemaParserCtxtPtr) ctxt;
@@ -2118,7 +2150,7 @@ xmlSchemaErr4Line(xmlSchemaAbstractCtxtPtr ctxt,
  *
  * Handle a validation error
  */
-static void
+static void LIBXML_ATTR_FORMAT(4,0)
 xmlSchemaErr3(xmlSchemaAbstractCtxtPtr actxt,
              int error, xmlNodePtr node, const char *msg,
              const xmlChar *str1, const xmlChar *str2, const xmlChar *str3)
@@ -2127,7 +2159,7 @@ xmlSchemaErr3(xmlSchemaAbstractCtxtPtr actxt,
        msg, str1, str2, str3, NULL);
 }
 
-static void
+static void LIBXML_ATTR_FORMAT(4,0)
 xmlSchemaErr4(xmlSchemaAbstractCtxtPtr actxt,
              int error, xmlNodePtr node, const char *msg,
              const xmlChar *str1, const xmlChar *str2,
@@ -2137,7 +2169,7 @@ xmlSchemaErr4(xmlSchemaAbstractCtxtPtr actxt,
        msg, str1, str2, str3, str4);
 }
 
-static void
+static void LIBXML_ATTR_FORMAT(4,0)
 xmlSchemaErr(xmlSchemaAbstractCtxtPtr actxt,
             int error, xmlNodePtr node, const char *msg,
             const xmlChar *str1, const xmlChar *str2)
@@ -2160,7 +2192,7 @@ xmlSchemaFormatNodeForError(xmlChar ** msg,
        /*
        * Don't try to format other nodes than element and
        * attribute nodes.
-       * Play save and return an empty string.
+       * Play safe and return an empty string.
        */
        *msg = xmlStrdup(BAD_CAST "");
        return(*msg);
@@ -2225,6 +2257,13 @@ xmlSchemaFormatNodeForError(xmlChar ** msg,
        TODO
        return (NULL);
     }
+
+    /*
+     * xmlSchemaFormatItemForReport() also returns an escaped format
+     * string, so do this before calling it below (in the future).
+     */
+    xmlEscapeFormatString(msg);
+
     /*
     * VAL TODO: The output of the given schema component is currently
     * disabled.
@@ -2241,7 +2280,7 @@ xmlSchemaFormatNodeForError(xmlChar ** msg,
     return (*msg);
 }
 
-static void
+static void LIBXML_ATTR_FORMAT(3,0)
 xmlSchemaInternalErr2(xmlSchemaAbstractCtxtPtr actxt,
                     const char *funcName,
                     const char *message,
@@ -2252,24 +2291,21 @@ xmlSchemaInternalErr2(xmlSchemaAbstractCtxtPtr actxt,
 
     if (actxt == NULL)
         return;
-    msg = xmlStrdup(BAD_CAST "Internal error: ");
-    msg = xmlStrcat(msg, BAD_CAST funcName);
-    msg = xmlStrcat(msg, BAD_CAST ", ");
+    msg = xmlStrdup(BAD_CAST "Internal error: %s, ");
     msg = xmlStrcat(msg, BAD_CAST message);
     msg = xmlStrcat(msg, BAD_CAST ".\n");
 
     if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR)
-       xmlSchemaErr(actxt, XML_SCHEMAV_INTERNAL, NULL,
-           (const char *) msg, str1, str2);
-
+       xmlSchemaErr3(actxt, XML_SCHEMAV_INTERNAL, NULL,
+           (const char *) msg, (const xmlChar *) funcName, str1, str2);
     else if (actxt->type == XML_SCHEMA_CTXT_PARSER)
-       xmlSchemaErr(actxt, XML_SCHEMAP_INTERNAL, NULL,
-           (const char *) msg, str1, str2);
+       xmlSchemaErr3(actxt, XML_SCHEMAP_INTERNAL, NULL,
+           (const char *) msg, (const xmlChar *) funcName, str1, str2);
 
     FREE_AND_NULL(msg)
 }
 
-static void
+static void LIBXML_ATTR_FORMAT(3,0)
 xmlSchemaInternalErr(xmlSchemaAbstractCtxtPtr actxt,
                     const char *funcName,
                     const char *message)
@@ -2278,7 +2314,7 @@ xmlSchemaInternalErr(xmlSchemaAbstractCtxtPtr actxt,
 }
 
 #if 0
-static void
+static void LIBXML_ATTR_FORMAT(3,0)
 xmlSchemaPInternalErr(xmlSchemaParserCtxtPtr pctxt,
                     const char *funcName,
                     const char *message,
@@ -2290,7 +2326,7 @@ xmlSchemaPInternalErr(xmlSchemaParserCtxtPtr pctxt,
 }
 #endif
 
-static void
+static void LIBXML_ATTR_FORMAT(5,0)
 xmlSchemaCustomErr4(xmlSchemaAbstractCtxtPtr actxt,
                   xmlParserErrors error,
                   xmlNodePtr node,
@@ -2315,7 +2351,7 @@ xmlSchemaCustomErr4(xmlSchemaAbstractCtxtPtr actxt,
     FREE_AND_NULL(msg)
 }
 
-static void
+static void LIBXML_ATTR_FORMAT(5,0)
 xmlSchemaCustomErr(xmlSchemaAbstractCtxtPtr actxt,
                   xmlParserErrors error,
                   xmlNodePtr node,
@@ -2330,7 +2366,7 @@ xmlSchemaCustomErr(xmlSchemaAbstractCtxtPtr actxt,
 
 
 
-static void
+static void LIBXML_ATTR_FORMAT(5,0)
 xmlSchemaCustomWarning(xmlSchemaAbstractCtxtPtr actxt,
                   xmlParserErrors error,
                   xmlNodePtr node,
@@ -2355,7 +2391,7 @@ xmlSchemaCustomWarning(xmlSchemaAbstractCtxtPtr actxt,
 
 
 
-static void
+static void LIBXML_ATTR_FORMAT(5,0)
 xmlSchemaKeyrefErr(xmlSchemaValidCtxtPtr vctxt,
                   xmlParserErrors error,
                   xmlSchemaPSVIIDCNodePtr idcNode,
@@ -2455,11 +2491,13 @@ xmlSchemaSimpleTypeErr(xmlSchemaAbstractCtxtPtr actxt,
        msg = xmlStrcat(msg, BAD_CAST " '");
        if (type->builtInType != 0) {
            msg = xmlStrcat(msg, BAD_CAST "xs:");
-           msg = xmlStrcat(msg, type->name);
-       } else
-           msg = xmlStrcat(msg,
-               xmlSchemaFormatQName(&str,
-                   type->targetNamespace, type->name));
+           str = xmlStrdup(type->name);
+       } else {
+           const xmlChar *qName = xmlSchemaFormatQName(&str, type->targetNamespace, type->name);
+           if (!str)
+               str = xmlStrdup(qName);
+       }
+       msg = xmlStrcat(msg, xmlEscapeFormatString(&str));
        msg = xmlStrcat(msg, BAD_CAST "'");
        FREE_AND_NULL(str);
     }
@@ -2504,7 +2542,7 @@ xmlSchemaIllegalAttrErr(xmlSchemaAbstractCtxtPtr actxt,
     FREE_AND_NULL(msg)
 }
 
-static void
+static void LIBXML_ATTR_FORMAT(5,0)
 xmlSchemaComplexTypeErr(xmlSchemaAbstractCtxtPtr actxt,
                        xmlParserErrors error,
                        xmlNodePtr node,
@@ -2596,7 +2634,7 @@ xmlSchemaComplexTypeErr(xmlSchemaAbstractCtxtPtr actxt,
                str = xmlStrcat(str, BAD_CAST ", ");
        }
        str = xmlStrcat(str, BAD_CAST " ).\n");
-       msg = xmlStrcat(msg, BAD_CAST str);
+       msg = xmlStrcat(msg, xmlEscapeFormatString(&str));
        FREE_AND_NULL(str)
     } else
       msg = xmlStrcat(msg, BAD_CAST "\n");
@@ -2604,7 +2642,7 @@ xmlSchemaComplexTypeErr(xmlSchemaAbstractCtxtPtr actxt,
     xmlFree(msg);
 }
 
-static void
+static void LIBXML_ATTR_FORMAT(8,0)
 xmlSchemaFacetErr(xmlSchemaAbstractCtxtPtr actxt,
                  xmlParserErrors error,
                  xmlNodePtr node,
@@ -2895,7 +2933,7 @@ xmlSchemaPIllegalAttrErr(xmlSchemaParserCtxtPtr ctxt,
  *
  * Reports an error during parsing.
  */
-static void
+static void LIBXML_ATTR_FORMAT(5,0)
 xmlSchemaPCustomErrExt(xmlSchemaParserCtxtPtr ctxt,
                    xmlParserErrors error,
                    xmlSchemaBasicItemPtr item,
@@ -2931,7 +2969,7 @@ xmlSchemaPCustomErrExt(xmlSchemaParserCtxtPtr ctxt,
  *
  * Reports an error during parsing.
  */
-static void
+static void LIBXML_ATTR_FORMAT(5,0)
 xmlSchemaPCustomErr(xmlSchemaParserCtxtPtr ctxt,
                    xmlParserErrors error,
                    xmlSchemaBasicItemPtr item,
@@ -2956,7 +2994,7 @@ xmlSchemaPCustomErr(xmlSchemaParserCtxtPtr ctxt,
  *
  * Reports an attribute use error during parsing.
  */
-static void
+static void LIBXML_ATTR_FORMAT(6,0)
 xmlSchemaPAttrUseErr4(xmlSchemaParserCtxtPtr ctxt,
                    xmlParserErrors error,
                    xmlNodePtr node,
@@ -3078,7 +3116,7 @@ xmlSchemaPMutualExclAttrErr(xmlSchemaParserCtxtPtr ctxt,
  * Reports a simple type validation error.
  * TODO: Should this report the value of an element as well?
  */
-static void
+static void LIBXML_ATTR_FORMAT(8,0)
 xmlSchemaPSimpleTypeErr(xmlSchemaParserCtxtPtr ctxt,
                        xmlParserErrors error,
                        xmlSchemaBasicItemPtr ownerItem ATTRIBUTE_UNUSED,
@@ -3120,11 +3158,13 @@ xmlSchemaPSimpleTypeErr(xmlSchemaParserCtxtPtr ctxt,
                msg = xmlStrcat(msg, BAD_CAST " '");
                if (type->builtInType != 0) {
                    msg = xmlStrcat(msg, BAD_CAST "xs:");
-                   msg = xmlStrcat(msg, type->name);
-               } else
-                   msg = xmlStrcat(msg,
-                       xmlSchemaFormatQName(&str,
-                           type->targetNamespace, type->name));
+                   str = xmlStrdup(type->name);
+               } else {
+                   const xmlChar *qName = xmlSchemaFormatQName(&str, type->targetNamespace, type->name);
+                   if (!str)
+                       str = xmlStrdup(qName);
+               }
+               msg = xmlStrcat(msg, xmlEscapeFormatString(&str));
                msg = xmlStrcat(msg, BAD_CAST "'.");
                FREE_AND_NULL(str);
            }
@@ -3136,8 +3176,10 @@ xmlSchemaPSimpleTypeErr(xmlSchemaParserCtxtPtr ctxt,
                "valid.");
        }
        if (expected) {
+           xmlChar *expectedEscaped = xmlCharStrdup(expected);
            msg = xmlStrcat(msg, BAD_CAST " Expected is '");
-           msg = xmlStrcat(msg, BAD_CAST expected);
+           msg = xmlStrcat(msg, xmlEscapeFormatString(&expectedEscaped));
+           FREE_AND_NULL(expectedEscaped);
            msg = xmlStrcat(msg, BAD_CAST "'.\n");
        } else
            msg = xmlStrcat(msg, BAD_CAST "\n");
@@ -3199,25 +3241,25 @@ xmlSchemaPContentErr(xmlSchemaParserCtxtPtr ctxt,
 }
 
 /************************************************************************
- *                                                                     *
- *                     Streamable error functions                      *
- *                                                                     *
+ *                                                                     *
+ *                     Streamable error functions                      *
+ *                                                                     *
  ************************************************************************/
 
 
 
 
 /************************************************************************
- *                                                                     *
- *                     Validation helper functions                     *
- *                                                                     *
+ *                                                                     *
+ *                     Validation helper functions                     *
+ *                                                                     *
  ************************************************************************/
 
 
 /************************************************************************
- *                                                                     *
- *                     Allocation functions                            *
- *                                                                     *
+ *                                                                     *
+ *                     Allocation functions                            *
+ *                                                                     *
  ************************************************************************/
 
 /**
@@ -4135,9 +4177,9 @@ xmlSchemaFree(xmlSchemaPtr schema)
 }
 
 /************************************************************************
- *                                                                     *
- *                     Debug functions                                 *
- *                                                                     *
+ *                                                                     *
+ *                     Debug functions                                 *
+ *                                                                     *
  ************************************************************************/
 
 #ifdef LIBXML_OUTPUT_ENABLED
@@ -4587,7 +4629,7 @@ xmlSchemaDebugDumpIDCTable(FILE * output,
 
 /************************************************************************
  *                                                                     *
- *                     Utilities                                       *
+ *                     Utilities                                       *
  *                                                                     *
  ************************************************************************/
 
@@ -4692,9 +4734,9 @@ xmlSchemaGetProp(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,
 }
 
 /************************************************************************
- *                                                                     *
- *                     Parsing functions                               *
- *                                                                     *
+ *                                                                     *
+ *                     Parsing functions                               *
+ *                                                                     *
  ************************************************************************/
 
 #define WXS_FIND_GLOBAL_ITEM(slot)                     \
@@ -4966,9 +5008,9 @@ xmlSchemaGetNamedComponent(xmlSchemaPtr schema,
 }
 
 /************************************************************************
- *                                                                     *
- *                     Parsing functions                               *
- *                                                                     *
+ *                                                                     *
+ *                     Parsing functions                               *
+ *                                                                     *
  ************************************************************************/
 
 #define IS_BLANK_NODE(n)                                               \
@@ -5743,9 +5785,9 @@ xmlSchemaAddElementSubstitutionMember(xmlSchemaParserCtxtPtr pctxt,
 }
 
 /************************************************************************
- *                                                                     *
+ *                                                                     *
  *             Utilities for parsing                                   *
- *                                                                     *
+ *                                                                     *
  ************************************************************************/
 
 /**
@@ -5939,7 +5981,7 @@ xmlSchemaPValAttrNodeID(xmlSchemaParserCtxtPtr ctxt, xmlAttrPtr attr)
                xmlFree((xmlChar *) value);
                value = strip;
            }
-           res = xmlAddID(NULL, attr->doc, value, attr);
+           res = xmlAddID(NULL, attr->doc, value, attr);
            if (res == NULL) {
                ret = XML_SCHEMAP_S4S_ATTR_INVALID_VALUE;
                xmlSchemaPSimpleTypeErr(ctxt,
@@ -6120,7 +6162,7 @@ xmlSchemaPGetBoolNodeValue(xmlSchemaParserCtxtPtr ctxt,
     value = xmlNodeGetContent(node);
     /*
     * 3.2.2.1 Lexical representation
-    * An instance of a datatype that is defined as �boolean�
+    * An instance of a datatype that is defined as `boolean`
     * can have the following legal literals {true, false, 1, 0}.
     */
     if (xmlStrEqual(BAD_CAST value, BAD_CAST "true"))
@@ -6168,7 +6210,7 @@ xmlGetBooleanProp(xmlSchemaParserCtxtPtr ctxt,
         return (def);
     /*
     * 3.2.2.1 Lexical representation
-    * An instance of a datatype that is defined as �boolean�
+    * An instance of a datatype that is defined as `boolean`
     * can have the following legal literals {true, false, 1, 0}.
     */
     if (xmlStrEqual(val, BAD_CAST "true"))
@@ -6191,9 +6233,9 @@ xmlGetBooleanProp(xmlSchemaParserCtxtPtr ctxt,
 }
 
 /************************************************************************
- *                                                                     *
+ *                                                                     *
  *             Shema extraction from an Infoset                        *
- *                                                                     *
+ *                                                                     *
  ************************************************************************/
 static xmlSchemaTypePtr xmlSchemaParseSimpleType(xmlSchemaParserCtxtPtr
                                                  ctxt, xmlSchemaPtr schema,
@@ -7698,8 +7740,8 @@ xmlSchemaParseAttributeGroupRef(xmlSchemaParserCtxtPtr pctxt,
        /*
        * SPEC src-redefine:
        * (7.1) "If it has an <attributeGroup> among its contents
-       * the �actual value� of whose ref [attribute] is the same
-       * as the �actual value� of its own name attribute plus
+       * the `actual value` of whose ref [attribute] is the same
+       * as the `actual value` of its own name attribute plus
        * target namespace, then it must have exactly one such group."
        */
        if (pctxt->redefCounter != 0) {
@@ -8227,7 +8269,7 @@ xmlSchemaParseIDCSelectorAndField(xmlSchemaParserCtxtPtr ctxt,
     */
     attr = xmlSchemaGetPropNode(node, "xpath");
     if (attr == NULL) {
-       xmlSchemaPMissingAttrErr(ctxt,
+       xmlSchemaPMissingAttrErr(ctxt,
            XML_SCHEMAP_S4S_ATTR_MISSING,
            NULL, node,
            "name", NULL);
@@ -8848,7 +8890,7 @@ xmlSchemaParseUnion(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
     type->flags |= XML_SCHEMAS_TYPE_VARIETY_UNION;
     /*
     * SPEC (Base type) (2) "If the <list> or <union> alternative is chosen,
-    * then the �simple ur-type definition�."
+    * then the `simple ur-type definition`."
     */
     type->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE);
     /*
@@ -9016,7 +9058,7 @@ xmlSchemaParseList(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
     type->flags |= XML_SCHEMAS_TYPE_VARIETY_LIST;
     /*
     * SPEC (Base type) (2) "If the <list> or <union> alternative is chosen,
-    * then the �simple ur-type definition�."
+    * then the `simple ur-type definition`."
     */
     type->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE);
     /*
@@ -9161,9 +9203,9 @@ xmlSchemaParseSimpleType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
     }
     /*
     * TargetNamespace:
-    * SPEC "The �actual value� of the targetNamespace [attribute]
+    * SPEC "The `actual value` of the targetNamespace [attribute]
     * of the <schema> ancestor element information item if present,
-    * otherwise �absent�.
+    * otherwise `absent`.
     */
     if (topLevel == 0) {
 #ifdef ENABLE_NAMED_LOCALS
@@ -9298,8 +9340,8 @@ xmlSchemaParseSimpleType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
     /*
     * REDEFINE: SPEC src-redefine (5)
     * "Within the [children], each <simpleType> must have a
-    * <restriction> among its [children] ... the �actual value� of whose
-    * base [attribute] must be the same as the �actual value� of its own
+    * <restriction> among its [children] ... the `actual value` of whose
+    * base [attribute] must be the same as the `actual value` of its own
     * name attribute plus target namespace;"
     */
     if (topLevel && ctxt->isRedefine && (! hasRestriction)) {
@@ -10383,7 +10425,7 @@ xmlSchemaAddSchemaDoc(xmlSchemaParserCtxtPtr pctxt,
        /*
        * Given that the schemaLocation [attribute] is only a hint, it is open
        * to applications to ignore all but the first <import> for a given
-       * namespace, regardless of the �actual value� of schemaLocation, but
+       * namespace, regardless of the `actual value` of schemaLocation, but
        * such a strategy risks missing useful information when new
        * schemaLocations are offered.
        *
@@ -10736,7 +10778,7 @@ xmlSchemaParseImport(xmlSchemaParserCtxtPtr pctxt, xmlSchemaPtr schema,
            XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
            NULL, node,
            xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI),
-           NULL, namespaceName, NULL, NULL, NULL);
+           NULL, schemaLocation, NULL, NULL, NULL);
        return (pctxt->err);
     }
     /*
@@ -10767,8 +10809,8 @@ xmlSchemaParseImport(xmlSchemaParserCtxtPtr pctxt, xmlSchemaPtr schema,
     thisTargetNamespace = WXS_BUCKET(pctxt)->origTargetNamespace;
     if (namespaceName != NULL) {
        /*
-       * 1.1 If the namespace [attribute] is present, then its �actual value�
-       * must not match the �actual value� of the enclosing <schema>'s
+       * 1.1 If the namespace [attribute] is present, then its `actual value`
+       * must not match the `actual value` of the enclosing <schema>'s
        * targetNamespace [attribute].
        */
        if (xmlStrEqual(thisTargetNamespace, namespaceName)) {
@@ -10969,7 +11011,7 @@ xmlSchemaParseIncludeOrRedefine(xmlSchemaParserCtxtPtr pctxt,
            * for inclusions, since the that was the feedback from the
            * schema people. I.e. the following spec piece will *not* be
            * satisfied:
-           * SPEC src-include: "It is not an error for the �actual value� of the
+           * SPEC src-include: "It is not an error for the `actual value` of the
            * schemaLocation [attribute] to fail to resolve it all, in which
            * case no corresponding inclusion is performed.
            * So do we need a warning report here?"
@@ -10986,7 +11028,7 @@ xmlSchemaParseIncludeOrRedefine(xmlSchemaParserCtxtPtr pctxt,
            *
            * SPEC src-redefine (1)
            * "If there are any element information items among the [children]
-           * other than <annotation> then the �actual value� of the
+           * other than <annotation> then the `actual value` of the
            * schemaLocation [attribute] must successfully resolve."
            * TODO: Ask the WG if a the location has always to resolve
            * here as well!
@@ -11006,9 +11048,9 @@ xmlSchemaParseIncludeOrRedefine(xmlSchemaParserCtxtPtr pctxt,
        if (bucket->origTargetNamespace != NULL) {
            /*
            * SPEC src-include (2.1)
-           * "SII has a targetNamespace [attribute], and its actual
-           * value� is identical to the �actual value� of the targetNamespace
-           * [attribute] of SII (which must have such an [attribute])."
+           * "SII has a targetNamespace [attribute], and its `actual
+           * value` is identical to the `actual value` of the targetNamespace
+           * [attribute] of SII' (which must have such an [attribute])."
            */
            if (pctxt->targetNamespace == NULL) {
                xmlSchemaCustomErr(ACTXT_CAST pctxt,
@@ -11356,8 +11398,8 @@ xmlSchemaParseModelGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
                        /*
                        * SPEC src-redefine:
                        * (6.1) "If it has a <group> among its contents at
-                       * some level the �actual value� of whose ref
-                       * [attribute] is the same as the �actual value� of
+                       * some level the `actual value` of whose ref
+                       * [attribute] is the same as the `actual value` of
                        * its own name attribute plus target namespace, then
                        * all of the following must be true:"
                        * (6.1.1) "It must have exactly one such group."
@@ -11382,9 +11424,9 @@ xmlSchemaParseModelGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
                            xmlChar *str = NULL;
                            /*
                            * SPEC src-redefine:
-                           * (6.1.2) "The �actual value� of both that
+                           * (6.1.2) "The `actual value` of both that
                            * group's minOccurs and maxOccurs [attribute]
-                           * must be 1 (or �absent�).
+                           * must be 1 (or `absent`).
                            */
                            xmlSchemaCustomErr(ACTXT_CAST ctxt,
                                XML_SCHEMAP_SRC_REDEFINE, child, NULL,
@@ -11498,8 +11540,8 @@ xmlSchemaParseRestriction(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
     *
     * SPEC (1.2) "...otherwise (<restriction> has no <simpleType> "
     * among its [children]), the simple type definition which is
-    * the {content type} of the type definition �resolved� to by
-    * the �actual value� of the base [attribute]"
+    * the {content type} of the type definition `resolved` to by
+    * the `actual value` of the base [attribute]"
     */
     if (xmlSchemaPValAttrQName(ctxt, schema, NULL, node, "base",
        &(type->baseNs), &(type->base)) == 0)
@@ -11522,8 +11564,8 @@ xmlSchemaParseRestriction(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
                /*
                * REDEFINE: SPEC src-redefine (5)
                * "Within the [children], each <simpleType> must have a
-               * <restriction> among its [children] ... the �actual value� of
-               * whose base [attribute] must be the same as the �actual value�
+               * <restriction> among its [children] ... the `actual value` of
+               * whose base [attribute] must be the same as the `actual value`
                * of its own name attribute plus target namespace;"
                */
                xmlSchemaPCustomErrExt(ctxt, XML_SCHEMAP_SRC_REDEFINE,
@@ -12284,7 +12326,7 @@ xmlSchemaParseComplexType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
        * SPEC
        * "...the third alternative (neither <simpleContent> nor
        * <complexContent>) is chosen. This case is understood as shorthand
-       * for complex content restricting the �ur-type definition�, and the
+       * for complex content restricting the `ur-type definition`, and the
        * details of the mappings should be modified as necessary.
        */
        type->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE);
@@ -12353,15 +12395,15 @@ xmlSchemaParseComplexType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
 }
 
 /************************************************************************
- *                                                                     *
- *                     Validating using Schemas                        *
- *                                                                     *
+ *                                                                     *
+ *                     Validating using Schemas                        *
+ *                                                                     *
  ************************************************************************/
 
 /************************************************************************
- *                                                                     *
- *                     Reading/Writing Schemas                         *
- *                                                                     *
+ *                                                                     *
+ *                     Reading/Writing Schemas                         *
+ *                                                                     *
  ************************************************************************/
 
 #if 0 /* Will be enabled if it is clear what options are needed. */
@@ -12938,6 +12980,15 @@ xmlSchemaBuildAContentModel(xmlSchemaParserCtxtPtr pctxt,
                         if (tmp2 != 1) ret = 0;
                         sub = sub->next;
                     }
+
+                   /*
+                    * epsilon needed to block previous trans from
+                    * being allowed to enter back from another
+                    * construct
+                    */
+                   pctxt->state = xmlAutomataNewEpsilon(pctxt->am,
+                                       pctxt->state, NULL);
+
                     if (particle->minOccurs == 0) {
                         xmlAutomataNewEpsilon(pctxt->am, oldstate,
                                               pctxt->state);
@@ -13183,8 +13234,8 @@ xmlSchemaResolveElementReferences(xmlSchemaElementPtr elemDecl,
     if ((elemDecl->subtypes == NULL) && (elemDecl->namedType != NULL)) {
        xmlSchemaTypePtr type;
 
-       /* (type definition) ... otherwise the type definition �resolved�
-       * to by the �actual value� of the type [attribute] ...
+       /* (type definition) ... otherwise the type definition `resolved`
+       * to by the `actual value` of the type [attribute] ...
        */
        type = xmlSchemaGetType(ctxt->schema, elemDecl->namedType,
            elemDecl->namedTypeNs);
@@ -13222,7 +13273,7 @@ xmlSchemaResolveElementReferences(xmlSchemaElementPtr elemDecl,
            /*
            * The type definitions is set to:
            * SPEC "...the {type definition} of the element
-           * declaration �resolved� to by the �actual value�
+           * declaration `resolved` to by the `actual value`
            * of the substitutionGroup [attribute], if present"
            */
            if (elemDecl->subtypes == NULL)
@@ -13260,8 +13311,8 @@ xmlSchemaResolveUnionMemberTypes(xmlSchemaParserCtxtPtr ctxt,
 
     /*
     * SPEC (1) "If the <union> alternative is chosen, then [Definition:]
-    * define the explicit members as the type definitions �resolved�
-    * to by the items in the �actual value� of the memberTypes [attribute],
+    * define the explicit members as the type definitions `resolved`
+    * to by the items in the `actual value` of the memberTypes [attribute],
     * if any, followed by the type definitions corresponding to the
     * <simpleType>s among the [children] of <union>, if any."
     */
@@ -13556,7 +13607,7 @@ xmlSchemaUnionWildcards(xmlSchemaParserCtxtPtr ctxt,
        return (0);
     }
     /*
-    * 3 If both O1 and O2 are sets of (namespace names or �absent�),
+    * 3 If both O1 and O2 are sets of (namespace names or `absent`),
     * then the union of those sets must be the value.
     */
     if ((completeWild->nsSet != NULL) && (curWild->nsSet != NULL)) {
@@ -13590,7 +13641,7 @@ xmlSchemaUnionWildcards(xmlSchemaParserCtxtPtr ctxt,
     }
     /*
     * 4 If the two are negations of different values (namespace names
-    * or �absent�), then a pair of not and �absent� must be the value.
+    * or `absent`), then a pair of not and `absent` must be the value.
     */
     if ((completeWild->negNsSet != NULL) &&
        (curWild->negNsSet != NULL) &&
@@ -13632,7 +13683,7 @@ xmlSchemaUnionWildcards(xmlSchemaParserCtxtPtr ctxt,
        if (nsFound && absentFound) {
            /*
            * 5.1 If the set S includes both the negated namespace
-           * name and �absent�, then any must be the value.
+           * name and `absent`, then any must be the value.
            */
            completeWild->any = 1;
            if (completeWild->nsSet != NULL) {
@@ -13646,7 +13697,7 @@ xmlSchemaUnionWildcards(xmlSchemaParserCtxtPtr ctxt,
        } else if (nsFound && (!absentFound)) {
            /*
            * 5.2 If the set S includes the negated namespace name
-           * but not �absent�, then a pair of not and �absent� must
+           * but not `absent`, then a pair of not and `absent` must
            * be the value.
            */
            if (completeWild->nsSet != NULL) {
@@ -13661,7 +13712,7 @@ xmlSchemaUnionWildcards(xmlSchemaParserCtxtPtr ctxt,
            completeWild->negNsSet->value = NULL;
        } else if ((!nsFound) && absentFound) {
            /*
-           * 5.3 If the set S includes �absent� but not the negated
+           * 5.3 If the set S includes `absent` but not the negated
            * namespace name, then the union is not expressible.
            */
            xmlSchemaPErr(ctxt, completeWild->node,
@@ -13672,7 +13723,7 @@ xmlSchemaUnionWildcards(xmlSchemaParserCtxtPtr ctxt,
        } else if ((!nsFound) && (!absentFound)) {
            /*
            * 5.4 If the set S does not include either the negated namespace
-           * name or �absent�, then whichever of O1 or O2 is a pair of not
+           * name or `absent`, then whichever of O1 or O2 is a pair of not
            * and a namespace name must be the value.
            */
            if (completeWild->negNsSet == NULL) {
@@ -13706,7 +13757,7 @@ xmlSchemaUnionWildcards(xmlSchemaParserCtxtPtr ctxt,
        while (cur != NULL) {
            if (cur->value == NULL) {
                /*
-               * 6.1 If the set S includes �absent�, then any must be the
+               * 6.1 If the set S includes `absent`, then any must be the
                * value.
                */
                completeWild->any = 1;
@@ -13724,8 +13775,8 @@ xmlSchemaUnionWildcards(xmlSchemaParserCtxtPtr ctxt,
        }
        if (completeWild->negNsSet == NULL) {
            /*
-           * 6.2 If the set S does not include �absent�, then a pair of not
-           * and �absent� must be the value.
+           * 6.2 If the set S does not include `absent`, then a pair of not
+           * and `absent` must be the value.
            */
            if (completeWild->nsSet != NULL) {
                xmlSchemaFreeWildcardNsSet(completeWild->nsSet);
@@ -13808,9 +13859,9 @@ xmlSchemaIntersectWildcards(xmlSchemaParserCtxtPtr ctxt,
     }
     /*
     * 3 If either O1 or O2 is a pair of not and a value (a namespace
-    * name or �absent�) and the other is a set of (namespace names or
-    * �absent�), then that set, minus the negated value if it was in
-    * the set, minus �absent� if it was in the set, must be the value.
+    * name or `absent`) and the other is a set of (namespace names or
+    * `absent`), then that set, minus the negated value if it was in
+    * the set, minus `absent` if it was in the set, must be the value.
     */
     if (((completeWild->negNsSet != NULL) && (curWild->nsSet != NULL)) ||
        ((curWild->negNsSet != NULL) && (completeWild->nsSet != NULL))) {
@@ -13859,7 +13910,7 @@ xmlSchemaIntersectWildcards(xmlSchemaParserCtxtPtr ctxt,
        return(0);
     }
     /*
-    * 4 If both O1 and O2 are sets of (namespace names or �absent�),
+    * 4 If both O1 and O2 are sets of (namespace names or `absent`),
     * then the intersection of those sets must be the value.
     */
     if ((completeWild->nsSet != NULL) && (curWild->nsSet != NULL)) {
@@ -13909,7 +13960,7 @@ xmlSchemaIntersectWildcards(xmlSchemaParserCtxtPtr ctxt,
     }
     /*
     * 6 If the one is a negation of a namespace name and the other
-    * is a negation of �absent�, then the one which is the negation
+    * is a negation of `absent`, then the one which is the negation
     * of a namespace name must be the value.
     */
     if ((completeWild->negNsSet != NULL) && (curWild->negNsSet != NULL) &&
@@ -13941,7 +13992,7 @@ xmlSchemaCheckCOSNSSubset(xmlSchemaWildcardPtr sub,
     if (super->any)
        return (0);
     /*
-    * 2.1 sub must be a pair of not and a namespace name or �absent�.
+    * 2.1 sub must be a pair of not and a namespace name or `absent`.
     * 2.2 super must be a pair of not and the same value.
     */
     if ((sub->negNsSet != NULL) &&
@@ -13949,7 +14000,7 @@ xmlSchemaCheckCOSNSSubset(xmlSchemaWildcardPtr sub,
        (sub->negNsSet->value == super->negNsSet->value))
        return (0);
     /*
-    * 3.1 sub must be a set whose members are either namespace names or �absent�.
+    * 3.1 sub must be a set whose members are either namespace names or `absent`.
     */
     if (sub->nsSet != NULL) {
        /*
@@ -13980,7 +14031,7 @@ xmlSchemaCheckCOSNSSubset(xmlSchemaWildcardPtr sub,
            xmlSchemaWildcardNsPtr cur;
            /*
            * 3.2.2 super must be a pair of not and a namespace name or
-           * �absent� and that value must not be in sub's set.
+           * `absent` and that value must not be in sub's set.
            */
            cur = sub->nsSet;
            while (cur != NULL) {
@@ -14142,7 +14193,7 @@ xmlSchemaCheckDerivationOKRestriction2to4(xmlSchemaParserCtxtPtr pctxt,
                        * SPEC (2.1.2) "R's {attribute declaration}'s
                        * {type definition} must be validly derived from
                        * B's {type definition} given the empty set as
-                       * defined in Type Derivation OK (Simple) (3.14.6)."
+                       * defined in Type Derivation OK (Simple) ($3.14.6)."
                        */
                        xmlSchemaPAttrUseErr4(pctxt,
                            XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_2,
@@ -14174,8 +14225,8 @@ xmlSchemaCheckDerivationOKRestriction2to4(xmlSchemaParserCtxtPtr pctxt,
                        /*
                        * 2.1.3 ... one of the following must be true
                        *
-                       * 2.1.3.1 B's �effective value constraint� is
-                       * �absent� or default.
+                       * 2.1.3.1 B's `effective value constraint` is
+                       * `absent` or default.
                        */
                        if ((bEffValue != NULL) &&
                            (effFixed == 1)) {
@@ -14184,7 +14235,7 @@ xmlSchemaCheckDerivationOKRestriction2to4(xmlSchemaParserCtxtPtr pctxt,
                            xmlSchemaGetEffectiveValueConstraint(bcur,
                                &effFixed, &rEffValue, NULL);
                            /*
-                           * 2.1.3.2 R's �effective value constraint� is
+                           * 2.1.3.2 R's `effective value constraint` is
                            * fixed with the same string as B's.
                            * MAYBE TODO: Compare the computed values.
                            *       Hmm, it says "same string" so
@@ -14218,9 +14269,9 @@ not_found:
                /*
                * (2.2) "otherwise the {base type definition} must have an
                * {attribute wildcard} and the {target namespace} of the
-               * R's {attribute declaration} must be �valid� with respect
+               * R's {attribute declaration} must be `valid` with respect
                * to that wildcard, as defined in Wildcard allows Namespace
-               * Name (3.10.4)."
+               * Name ($3.10.4)."
                */
                if ((baseWild == NULL) ||
                    (xmlSchemaCheckCVCWildcardNamespace(baseWild,
@@ -14318,7 +14369,7 @@ not_found:
            * (4.2) "The complex type definition's {attribute wildcard}'s
            * {namespace constraint} must be a subset of the {base type
            * definition}'s {attribute wildcard}'s {namespace constraint},
-           * as defined by Wildcard Subset (3.10.6)."
+           * as defined by Wildcard Subset ($3.10.6)."
            */
            xmlSchemaCustomErr4(ACTXT_CAST pctxt,
                XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_2,
@@ -14332,8 +14383,8 @@ not_found:
            FREE_AND_NULL(str);
            return(pctxt->err);
        }
-       /* 4.3 Unless the {base type definition} is the ur-type
-       * definition, the complex type definition's {attribute
+       /* 4.3 Unless the {base type definition} is the `ur-type
+       * definition`, the complex type definition's {attribute
        * wildcard}'s {process contents} must be identical to or
        * stronger than the {base type definition}'s {attribute
        * wildcard}'s {process contents}, where strict is stronger
@@ -14519,7 +14570,7 @@ inherit_next: {}
     if (WXS_IS_EXTENSION(type)) {
        if (baseType->attributeWildcard != NULL) {
            /*
-           * (3.2.2.1) "If the �base wildcard� is non-�absent�, then
+           * (3.2.2.1) "If the `base wildcard` is non-`absent`, then
            * the appropriate case among the following:"
            */
            if (type->attributeWildcard != NULL) {
@@ -14527,26 +14578,26 @@ inherit_next: {}
                * Union the complete wildcard with the base wildcard.
                * SPEC {attribute wildcard}
                * (3.2.2.1.2) "otherwise a wildcard whose {process contents}
-               * and {annotation} are those of the �complete wildcard�,
+               * and {annotation} are those of the `complete wildcard`,
                * and whose {namespace constraint} is the intensional union
-               * of the {namespace constraint} of the �complete wildcard�
-               * and of the �base wildcard�, as defined in Attribute
-               * Wildcard Union (3.10.6)."
+               * of the {namespace constraint} of the `complete wildcard`
+               * and of the `base wildcard`, as defined in Attribute
+               * Wildcard Union ($3.10.6)."
                */
                if (xmlSchemaUnionWildcards(pctxt, type->attributeWildcard,
                    baseType->attributeWildcard) == -1)
                    goto exit_failure;
            } else {
                /*
-               * (3.2.2.1.1) "If the �complete wildcard� is �absent�,
-               * then the �base wildcard�."
+               * (3.2.2.1.1) "If the `complete wildcard` is `absent`,
+               * then the `base wildcard`."
                */
                type->attributeWildcard = baseType->attributeWildcard;
            }
        } else {
            /*
-           * (3.2.2.2) "otherwise (the �base wildcard� is �absent�) the
-           * �complete wildcard"
+           * (3.2.2.2) "otherwise (the `base wildcard` is `absent`) the
+           * `complete wildcard`"
            * NOOP
            */
        }
@@ -14554,7 +14605,7 @@ inherit_next: {}
        /*
        * SPEC {attribute wildcard}
        * (3.1) "If the <restriction> alternative is chosen, then the
-       * �complete wildcard�;"
+       * `complete wildcard`;"
        * NOOP
        */
     }
@@ -14803,12 +14854,12 @@ xmlSchemaCheckCOSSTDerivedOK(xmlSchemaAbstractCtxtPtr actxt,
     /* 2.2 */
     if (type->baseType == baseType) {
        /*
-       * 2.2.1 D's �base type definition� is B.
+       * 2.2.1 D's `base type definition` is B.
        */
        return (0);
     }
     /*
-    * 2.2.2 D's �base type definition� is not the �ur-type definition�
+    * 2.2.2 D's `base type definition` is not the `ur-type definition`
     * and is validly derived from B given the subset, as defined by this
     * constraint.
     */
@@ -14818,8 +14869,8 @@ xmlSchemaCheckCOSSTDerivedOK(xmlSchemaAbstractCtxtPtr actxt,
        return (0);
     }
     /*
-    * 2.2.3 D's {variety} is list or union and B is the simple ur-type
-    * definition.
+    * 2.2.3 D's {variety} is list or union and B is the `simple ur-type
+    * definition`.
     */
     if (WXS_IS_ANY_SIMPLE_TYPE(baseType) &&
        (WXS_IS_LIST(type) || WXS_IS_UNION(type))) {
@@ -15131,14 +15182,14 @@ xmlSchemaCheckSTPropsCorrect(xmlSchemaParserCtxtPtr ctxt,
     * NOTE: This is somehow redundant, since we actually built a simple type
     * to have all the needed information; this acts as an self test.
     */
-    /* Base type: If the datatype has been �derived� by �restriction�
-    * then the Simple Type Definition component from which it is �derived�,
-    * otherwise the Simple Type Definition for anySimpleType (4.1.6).
+    /* Base type: If the datatype has been `derived` by `restriction`
+    * then the Simple Type Definition component from which it is `derived`,
+    * otherwise the Simple Type Definition for anySimpleType ($4.1.6).
     */
     if (baseType == NULL) {
        /*
        * TODO: Think about: "modulo the impact of Missing
-       * Sub-components (5.3)."
+       * Sub-components ($5.3)."
        */
        xmlSchemaPCustomErr(ctxt,
            XML_SCHEMAP_ST_PROPS_CORRECT_1,
@@ -15198,10 +15249,10 @@ xmlSchemaCheckSTPropsCorrect(xmlSchemaParserCtxtPtr ctxt,
     }
 
     /*
-    * 2 All simple type definitions must be derived ultimately from the simple
-    * ur-type definition (so� circular definitions are disallowed). That is, it
-    * must be possible to reach a built-in primitive datatype or the simple
-    * ur-type definition by repeatedly following the {base type definition}.
+    * 2 All simple type definitions must be derived ultimately from the `simple
+    * ur-type definition` (so circular definitions are disallowed). That is, it
+    * must be possible to reach a built-in primitive datatype or the `simple
+    * ur-type definition` by repeatedly following the {base type definition}.
     *
     * NOTE: this is done in xmlSchemaCheckTypeDefCircular().
     */
@@ -15385,10 +15436,10 @@ xmlSchemaCheckCOSSTRestricts(xmlSchemaParserCtxtPtr pctxt,
            }
            /*
            * MAYBE TODO: (Hmm, not really) Datatypes states:
-           * A �list� datatype can be �derived� from an �atomic� datatype
-           * whose �lexical space� allows space (such as string or anyURI)or
-           * a �union� datatype any of whose {member type definitions}'s
-           * �lexical space� allows space.
+           * A `list` datatype can be `derived` from an `atomic` datatype
+           * whose `lexical space` allows space (such as string or anyURI)or
+           * a `union` datatype any of whose {member type definitions}'s
+           * `lexical space` allows space.
            */
        } else {
            /*
@@ -15425,7 +15476,7 @@ xmlSchemaCheckCOSSTRestricts(xmlSchemaParserCtxtPtr pctxt,
            /*
            * 2.3.2.3 The {item type definition} must be validly derived
            * from the {base type definition}'s {item type definition} given
-           * the empty set, as defined in Type Derivation OK (Simple) (3.14.6).
+           * the empty set, as defined in Type Derivation OK (Simple) ($3.14.6).
            */
            {
                xmlSchemaTypePtr baseItemType;
@@ -15472,7 +15523,7 @@ xmlSchemaCheckCOSSTRestricts(xmlSchemaParserCtxtPtr pctxt,
                        case XML_SCHEMA_FACET_WHITESPACE:
                            /*
                            * TODO: 2.5.1.2 List datatypes
-                           * The value of �whiteSpace� is fixed to the value collapse.
+                           * The value of `whiteSpace` is fixed to the value collapse.
                            */
                        case XML_SCHEMA_FACET_PATTERN:
                        case XML_SCHEMA_FACET_ENUMERATION:
@@ -15525,8 +15576,8 @@ xmlSchemaCheckCOSSTRestricts(xmlSchemaParserCtxtPtr pctxt,
            member = member->next;
        }
        /*
-       * 3.3.1 If the {base type definition} is the simple ur-type
-       * definition
+       * 3.3.1 If the {base type definition} is the `simple ur-type
+       * definition`
        */
        if (type->baseType->builtInType == XML_SCHEMAS_ANYSIMPLETYPE) {
            /*
@@ -15588,7 +15639,7 @@ xmlSchemaCheckCOSSTRestricts(xmlSchemaParserCtxtPtr pctxt,
            * 3.3.2.3 The {member type definitions}, in order, must be validly
            * derived from the corresponding type definitions in the {base
            * type definition}'s {member type definitions} given the empty set,
-           * as defined in Type Derivation OK (Simple) (3.14.6).
+           * as defined in Type Derivation OK (Simple) ($3.14.6).
            */
            {
                xmlSchemaTypeLinkPtr baseMember;
@@ -15695,7 +15746,7 @@ xmlSchemaCheckSRCSimpleType(xmlSchemaParserCtxtPtr ctxt,
     /*
     * src-simple-type.1 The corresponding simple type definition, if any,
     * must satisfy the conditions set out in Constraints on Simple Type
-    * Definition Schema Components (3.14.6).
+    * Definition Schema Components ($3.14.6).
     */
     if (WXS_IS_RESTRICTION(type)) {
        /*
@@ -15793,8 +15844,8 @@ xmlSchemaParseCheckCOSValidDefault(xmlSchemaParserCtxtPtr pctxt,
        * SPEC (2.1) "its {content type} must be a simple type definition
        * or mixed."
        * SPEC (2.2.2) "If the {content type} is mixed, then the {content
-       * type}'s particle must be �emptiable� as defined by
-       * Particle Emptiable (3.9.6)."
+       * type}'s particle must be `emptiable` as defined by
+       * Particle Emptiable ($3.9.6)."
        */
        if ((! WXS_HAS_SIMPLE_CONTENT(type)) &&
            ((! WXS_HAS_MIXED_CONTENT(type)) || (! WXS_EMPTIABLE(type)))) {
@@ -15810,14 +15861,14 @@ xmlSchemaParseCheckCOSValidDefault(xmlSchemaParserCtxtPtr pctxt,
     }
     /*
     * 1 If the type definition is a simple type definition, then the string
-    * must be �valid� with respect to that definition as defined by String
-    * Valid (3.14.4).
+    * must be `valid` with respect to that definition as defined by String
+    * Valid ($3.14.4).
     *
     * AND
     *
     * 2.2.1 If the {content type} is a simple type definition, then the
-    * string must be �valid� with respect to that simple type definition
-    * as defined by String Valid (3.14.4).
+    * string must be `valid` with respect to that simple type definition
+    * as defined by String Valid ($3.14.4).
     */
     if (WXS_IS_SIMPLE(type))
        ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST pctxt, node,
@@ -15847,7 +15898,7 @@ xmlSchemaParseCheckCOSValidDefault(xmlSchemaParserCtxtPtr pctxt,
  * STATUS: (seems) complete
  *
  * Returns 0 if the constraints are satisfied, a positive
- * error code if not and -1 if an internal error occured.
+ * error code if not and -1 if an internal error occurred.
  */
 static int
 xmlSchemaCheckCTPropsCorrect(xmlSchemaParserCtxtPtr pctxt,
@@ -15858,8 +15909,8 @@ xmlSchemaCheckCTPropsCorrect(xmlSchemaParserCtxtPtr pctxt,
     *
     * SPEC (1) "The values of the properties of a complex type definition must
     * be as described in the property tableau in The Complex Type Definition
-    * Schema Component (3.4.1), modulo the impact of Missing
-    * Sub-components (5.3)."
+    * Schema Component ($3.4.1), modulo the impact of Missing
+    * Sub-components ($5.3)."
     */
     if ((type->baseType != NULL) &&
        (WXS_IS_SIMPLE(type->baseType)) &&
@@ -15876,9 +15927,9 @@ xmlSchemaCheckCTPropsCorrect(xmlSchemaParserCtxtPtr pctxt,
        return (XML_SCHEMAP_SRC_CT_1);
     }
     /*
-    * SPEC (3) "Circular definitions are disallowed, except for the ur-type
-    * definition�. That is, it must be possible to reach the �ur-type
-    * definition by repeatedly following the {base type definition}."
+    * SPEC (3) "Circular definitions are disallowed, except for the `ur-type
+    * definition`. That is, it must be possible to reach the `ur-type
+    * definition` by repeatedly following the {base type definition}."
     *
     * NOTE (3) is done in xmlSchemaCheckTypeDefCircular().
     */
@@ -16030,8 +16081,8 @@ xmlSchemaCheckCOSCTDerivedOK(xmlSchemaAbstractCtxtPtr actxt,
     if (type->baseType == baseType)
        return (0);
     /*
-    * SPEC (2.3.1) "D's {base type definition} must not be the ur-type
-    * definition."
+    * SPEC (2.3.1) "D's {base type definition} must not be the `ur-type
+    * definition`."
     */
     if (WXS_IS_ANYTYPE(type->baseType))
        return (1);
@@ -16048,7 +16099,7 @@ xmlSchemaCheckCOSCTDerivedOK(xmlSchemaAbstractCtxtPtr actxt,
        /*
        * SPEC (2.3.2.2) "If D's {base type definition} is simple, then it
        * must be validly derived from B given the subset as defined in Type
-       * Derivation OK (Simple) (3.14.6).
+       * Derivation OK (Simple) ($3.14.6).
        */
        return (xmlSchemaCheckCOSSTDerivedOK(actxt, type->baseType,
            baseType, set));
@@ -16094,7 +16145,7 @@ xmlSchemaCheckCOSDerivedOK(xmlSchemaAbstractCtxtPtr actxt,
  *     (1.4.3.2.2.2) "Particle Valid (Extension)"
  *
  * Returns 0 if the constraints are satisfied, a positive
- * error code if not and -1 if an internal error occured.
+ * error code if not and -1 if an internal error occurred.
  */
 static int
 xmlSchemaCheckCOSCTExtends(xmlSchemaParserCtxtPtr ctxt,
@@ -16188,7 +16239,7 @@ xmlSchemaCheckCOSCTExtends(xmlSchemaParserCtxtPtr ctxt,
        * definition must also have one, and the base type definition's
        * {attribute  wildcard}'s {namespace constraint} must be a subset
        * of the complex  type definition's {attribute wildcard}'s {namespace
-       * constraint}, as defined by Wildcard Subset (3.10.6)."
+       * constraint}, as defined by Wildcard Subset ($3.10.6)."
        */
 
        /*
@@ -16285,9 +16336,9 @@ xmlSchemaCheckCOSCTExtends(xmlSchemaParserCtxtPtr ctxt,
                }
                /*
                * URGENT TODO SPEC (1.4.3.2.2.2) "The particle of the
-               * complex type definition must be a �valid extension�
+               * complex type definition must be a `valid extension`
                * of the {base type definition}'s particle, as defined
-               * in Particle Valid (Extension) (3.9.6)."
+               * in Particle Valid (Extension) ($3.9.6)."
                *
                * NOTE that we won't check "Particle Valid (Extension)",
                * since it is ensured by the derivation process in
@@ -16351,7 +16402,7 @@ xmlSchemaCheckCOSCTExtends(xmlSchemaParserCtxtPtr ctxt,
  * Validation Rule: Checking complex type subsumption
  *
  * Returns 0 if the constraints are satisfied, a positive
- * error code if not and -1 if an internal error occured.
+ * error code if not and -1 if an internal error occurred.
  */
 static int
 xmlSchemaCheckDerivationOKRestriction(xmlSchemaParserCtxtPtr ctxt,
@@ -16404,7 +16455,7 @@ xmlSchemaCheckDerivationOKRestriction(xmlSchemaParserCtxtPtr ctxt,
     if (base->builtInType == XML_SCHEMAS_ANYTYPE) {
        /*
        * SPEC (5.1) "The {base type definition} must be the
-       * �ur-type definition�."
+       * `ur-type definition`."
        * PASS
        */
     } else if ((type->contentType == XML_SCHEMA_CONTENT_SIMPLE) ||
@@ -16423,7 +16474,7 @@ xmlSchemaCheckDerivationOKRestriction(xmlSchemaParserCtxtPtr ctxt,
            * SPEC (5.2.2.1) "The {content type} of the {base type
            * definition} must be a simple type definition from which
            * the {content type} is validly derived given the empty
-           * set as defined in Type Derivation OK (Simple) (3.14.6)."
+           * set as defined in Type Derivation OK (Simple) ($3.14.6)."
            *
            * ATTENTION TODO: This seems not needed if the type implicitely
            * derived from the base type.
@@ -16454,8 +16505,8 @@ xmlSchemaCheckDerivationOKRestriction(xmlSchemaParserCtxtPtr ctxt,
                (xmlSchemaParticlePtr) base->subtypes))) {
            /*
            * SPEC (5.2.2.2) "The {base type definition} must be mixed
-           * and have a particle which is �emptiable� as defined in
-           * Particle Emptiable (3.9.6)."
+           * and have a particle which is `emptiable` as defined in
+           * Particle Emptiable ($3.9.6)."
            * PASS
            */
        } else {
@@ -16484,7 +16535,7 @@ xmlSchemaCheckDerivationOKRestriction(xmlSchemaParserCtxtPtr ctxt,
            /*
            * SPEC (5.3.2.2) "The {content type} of the {base type
            * definition} must be elementOnly or mixed and have a particle
-           * which is �emptiable� as defined in Particle Emptiable (�3.9.6)."
+           * which is `emptiable` as defined in Particle Emptiable ($3.9.6)."
            * PASS
            */
        } else {
@@ -16517,9 +16568,9 @@ xmlSchemaCheckDerivationOKRestriction(xmlSchemaParserCtxtPtr ctxt,
        }
        /*
        * SPEC (5.4.2) "The particle of the complex type definition itself
-       * must be a �valid restriction� of the particle of the {content
+       * must be a `valid restriction` of the particle of the {content
        * type} of the {base type definition} as defined in Particle Valid
-       * (Restriction) (3.9.6).
+       * (Restriction) ($3.9.6).
        *
        * URGENT TODO: (5.4.2)
        */
@@ -16541,7 +16592,7 @@ xmlSchemaCheckDerivationOKRestriction(xmlSchemaParserCtxtPtr ctxt,
  * (3.4.6) Constraints on Complex Type Definition Schema Components
  *
  * Returns 0 if the constraints are satisfied, a positive
- * error code if not and -1 if an internal error occured.
+ * error code if not and -1 if an internal error occurred.
  */
 static int
 xmlSchemaCheckCTComponent(xmlSchemaParserCtxtPtr ctxt,
@@ -16571,7 +16622,7 @@ xmlSchemaCheckCTComponent(xmlSchemaParserCtxtPtr ctxt,
  * Complex Type Definition Representation OK (src-ct)
  *
  * Returns 0 if the constraints are satisfied, a positive
- * error code if not and -1 if an internal error occured.
+ * error code if not and -1 if an internal error occurred.
  */
 static int
 xmlSchemaCheckSRCCT(xmlSchemaParserCtxtPtr ctxt,
@@ -16588,7 +16639,7 @@ xmlSchemaCheckSRCCT(xmlSchemaParserCtxtPtr ctxt,
     if (! WXS_HAS_SIMPLE_CONTENT(type)) {
        /*
        * 1 If the <complexContent> alternative is chosen, the type definition
-       * �resolved� to by the �actual value� of the base [attribute]
+       * `resolved` to by the `actual value` of the base [attribute]
        * must be a complex type definition;
        */
        if (! WXS_IS_COMPLEX(base)) {
@@ -16608,7 +16659,7 @@ xmlSchemaCheckSRCCT(xmlSchemaParserCtxtPtr ctxt,
        * SPEC
        * 2 If the <simpleContent> alternative is chosen, all of the
        * following must be true:
-       * 2.1 The type definition �resolved� to by the �actual value� of the
+       * 2.1 The type definition `resolved` to by the `actual value` of the
        * base [attribute] must be one of the following:
        */
        if (WXS_IS_SIMPLE(base)) {
@@ -16714,14 +16765,14 @@ xmlSchemaCheckSRCCT(xmlSchemaParserCtxtPtr ctxt,
     /*
     * SPEC (3) "The corresponding complex type definition component must
     * satisfy the conditions set out in Constraints on Complex Type
-    * Definition Schema Components (3.4.6);"
+    * Definition Schema Components ($3.4.6);"
     * NOTE (3) will be done in xmlSchemaTypeFixup().
     */
     /*
     * SPEC (4) If clause 2.2.1 or clause 2.2.2 in the correspondence specification
     * above for {attribute wildcard} is satisfied, the intensional
     * intersection must be expressible, as defined in Attribute Wildcard
-    * Intersection (3.10.6).
+    * Intersection ($3.10.6).
     * NOTE (4) is done in xmlSchemaFixupTypeAttributeUses().
     */
     return (ret);
@@ -16740,7 +16791,7 @@ xmlSchemaCheckSRCCT(xmlSchemaParserCtxtPtr ctxt,
  * STATUS: complete
  *
  * Returns 0 if the constraints are satisfied, a positive
- * error code if not and -1 if an internal error occured.
+ * error code if not and -1 if an internal error occurred.
  */
 static int
 xmlSchemaCheckParticleRangeOK(int rmin, int rmax,
@@ -16770,7 +16821,7 @@ xmlSchemaCheckParticleRangeOK(int rmin, int rmax,
  *   CLARIFY: (3.2.2)
  *
  * Returns 0 if the constraints are satisfied, a positive
- * error code if not and -1 if an internal error occured.
+ * error code if not and -1 if an internal error occurred.
  */
 static int
 xmlSchemaCheckRCaseNameAndTypeOK(xmlSchemaParserCtxtPtr ctxt,
@@ -16792,7 +16843,7 @@ xmlSchemaCheckRCaseNameAndTypeOK(xmlSchemaParserCtxtPtr ctxt,
        return (1);
     /*
     * SPEC (2) "R's occurrence range is a valid restriction of B's
-    * occurrence range as defined by Occurrence Range OK (3.9.6)."
+    * occurrence range as defined by Occurrence Range OK ($3.9.6)."
     */
     if (xmlSchemaCheckParticleRangeOK(r->minOccurs, r->maxOccurs,
            b->minOccurs, b->maxOccurs) != 0)
@@ -16875,7 +16926,7 @@ xmlSchemaCheckRCaseNameAndTypeOK(xmlSchemaParserCtxtPtr ctxt,
  * STATUS: complete
  *
  * Returns 0 if the constraints are satisfied, a positive
- * error code if not and -1 if an internal error occured.
+ * error code if not and -1 if an internal error occurred.
  */
 static int
 xmlSchemaCheckRCaseNSCompat(xmlSchemaParserCtxtPtr ctxt,
@@ -16884,19 +16935,19 @@ xmlSchemaCheckRCaseNSCompat(xmlSchemaParserCtxtPtr ctxt,
 {
     /* TODO:Error codes (rcase-NSCompat). */
     /*
-    * SPEC "For an element declaration particle to be a �valid restriction�
+    * SPEC "For an element declaration particle to be a `valid restriction`
     * of a wildcard particle all of the following must be true:"
     *
-    * SPEC (1) "The element declaration's {target namespace} is �valid�
+    * SPEC (1) "The element declaration's {target namespace} is `valid`
     * with respect to the wildcard's {namespace constraint} as defined by
-    * Wildcard allows Namespace Name (3.10.4)."
+    * Wildcard allows Namespace Name ($3.10.4)."
     */
     if (xmlSchemaCheckCVCWildcardNamespace((xmlSchemaWildcardPtr) b->children,
        ((xmlSchemaElementPtr) r->children)->targetNamespace) != 0)
        return (1);
     /*
     * SPEC (2) "R's occurrence range is a valid restriction of B's
-    * occurrence range as defined by Occurrence Range OK (3.9.6)."
+    * occurrence range as defined by Occurrence Range OK ($3.9.6)."
     */
     if (xmlSchemaCheckParticleRangeOK(r->minOccurs, r->maxOccurs,
            b->minOccurs, b->maxOccurs) != 0)
@@ -16919,7 +16970,7 @@ xmlSchemaCheckRCaseNSCompat(xmlSchemaParserCtxtPtr ctxt,
  * STATUS: TODO
  *
  * Returns 0 if the constraints are satisfied, a positive
- * error code if not and -1 if an internal error occured.
+ * error code if not and -1 if an internal error occurred.
  */
 static int
 xmlSchemaCheckRCaseRecurseAsIfGroup(xmlSchemaParserCtxtPtr ctxt,
@@ -16945,7 +16996,7 @@ xmlSchemaCheckRCaseRecurseAsIfGroup(xmlSchemaParserCtxtPtr ctxt,
  * STATUS: complete
  *
  * Returns 0 if the constraints are satisfied, a positive
- * error code if not and -1 if an internal error occured.
+ * error code if not and -1 if an internal error occurred.
  */
 static int
 xmlSchemaCheckRCaseNSSubset(xmlSchemaParserCtxtPtr ctxt,
@@ -16956,21 +17007,21 @@ xmlSchemaCheckRCaseNSSubset(xmlSchemaParserCtxtPtr ctxt,
     /* TODO: Error codes (rcase-NSSubset). */
     /*
     * SPEC (1) "R's occurrence range is a valid restriction of B's
-    * occurrence range as defined by Occurrence Range OK (3.9.6)."
+    * occurrence range as defined by Occurrence Range OK ($3.9.6)."
     */
     if (xmlSchemaCheckParticleRangeOK(r->minOccurs, r->maxOccurs,
            b->minOccurs, b->maxOccurs))
        return (1);
     /*
     * SPEC (2) "R's {namespace constraint} must be an intensional subset
-    * of B's {namespace constraint} as defined by Wildcard Subset (3.10.6)."
+    * of B's {namespace constraint} as defined by Wildcard Subset ($3.10.6)."
     */
     if (xmlSchemaCheckCOSNSSubset((xmlSchemaWildcardPtr) r->children,
        (xmlSchemaWildcardPtr) b->children))
        return (1);
     /*
-    * SPEC (3) "Unless B is the content model wildcard of the ur-type
-    * definition, R's {process contents} must be identical to or stronger
+    * SPEC (3) "Unless B is the content model wildcard of the `ur-type
+    * definition`, R's {process contents} must be identical to or stronger
     * than B's {process contents}, where strict is stronger than lax is
     * stronger than skip."
     */
@@ -16995,7 +17046,7 @@ xmlSchemaCheckRCaseNSSubset(xmlSchemaParserCtxtPtr ctxt,
  * STATUS: TODO
  *
  * Returns 0 if the constraints are satisfied, a positive
- * error code if not and -1 if an internal error occured.
+ * error code if not and -1 if an internal error occurred.
  */
 static int
 xmlSchemaCheckCOSParticleRestrict(xmlSchemaParserCtxtPtr ctxt,
@@ -17036,7 +17087,7 @@ xmlSchemaCheckCOSParticleRestrict(xmlSchemaParserCtxtPtr ctxt,
  * STATUS: TODO: subst-groups
  *
  * Returns 0 if the constraints are satisfied, a positive
- * error code if not and -1 if an internal error occured.
+ * error code if not and -1 if an internal error occurred.
  */
 static int
 xmlSchemaCheckRCaseNSRecurseCheckCardinality(xmlSchemaParserCtxtPtr ctxt,
@@ -17048,12 +17099,12 @@ xmlSchemaCheckRCaseNSRecurseCheckCardinality(xmlSchemaParserCtxtPtr ctxt,
     if ((r->children == NULL) || (r->children->children == NULL))
        return (-1);
     /*
-    * SPEC "For a group particle to be a �valid restriction� of a
+    * SPEC "For a group particle to be a `valid restriction` of a
     * wildcard particle..."
     *
-    * SPEC (1) "Every member of the {particles} of the group is a valid
-    * restriction of the wildcard as defined by
-    * Particle Valid (Restriction) (3.9.6)."
+    * SPEC (1) "Every member of the {particles} of the group is a `valid
+    * restriction` of the wildcard as defined by
+    * Particle Valid (Restriction) ($3.9.6)."
     */
     part = (xmlSchemaParticlePtr) r->children->children;
     do {
@@ -17064,7 +17115,7 @@ xmlSchemaCheckRCaseNSRecurseCheckCardinality(xmlSchemaParserCtxtPtr ctxt,
     /*
     * SPEC (2) "The effective total range of the group [...] is a
     * valid restriction of B's occurrence range as defined by
-    * Occurrence Range OK (3.9.6)."
+    * Occurrence Range OK ($3.9.6)."
     */
     if (xmlSchemaCheckParticleRangeOK(
            xmlSchemaGetParticleTotalRangeMin(r),
@@ -17091,7 +17142,7 @@ xmlSchemaCheckRCaseNSRecurseCheckCardinality(xmlSchemaParserCtxtPtr ctxt,
  * TODO: subst-groups
  *
  * Returns 0 if the constraints are satisfied, a positive
- * error code if not and -1 if an internal error occured.
+ * error code if not and -1 if an internal error occurred.
  */
 static int
 xmlSchemaCheckRCaseRecurse(xmlSchemaParserCtxtPtr ctxt,
@@ -17104,11 +17155,11 @@ xmlSchemaCheckRCaseRecurse(xmlSchemaParserCtxtPtr ctxt,
        (r->children->type != b->children->type))
        return (-1);
     /*
-    * SPEC "For an all or sequence group particle to be a valid
-    * restriction of another group particle with the same {compositor}..."
+    * SPEC "For an all or sequence group particle to be a `valid
+    * restriction` of another group particle with the same {compositor}..."
     *
     * SPEC (1) "R's occurrence range is a valid restriction of B's
-    * occurrence range as defined by Occurrence Range OK (3.9.6)."
+    * occurrence range as defined by Occurrence Range OK ($3.9.6)."
     */
     if (xmlSchemaCheckParticleRangeOK(r->minOccurs, r->maxOccurs,
            b->minOccurs, b->maxOccurs))
@@ -17721,7 +17772,7 @@ xmlSchemaDeriveAndValidateFacets(xmlSchemaParserCtxtPtr pctxt,
     return (0);
 internal_error:
     PERROR_INT("xmlSchemaDeriveAndValidateFacets",
-       "an error occured");
+       "an error occurred");
     return (-1);
 }
 
@@ -17732,7 +17783,7 @@ xmlSchemaFinishMemberTypeDefinitionsProperty(xmlSchemaParserCtxtPtr pctxt,
     xmlSchemaTypeLinkPtr link, lastLink, prevLink, subLink, newLink;
     /*
     * The actual value is then formed by replacing any union type
-    * definition in the �explicit members� with the members of their
+    * definition in the `explicit members` with the members of their
     * {member type definitions}, in order.
     *
     * TODO: There's a bug entry at
@@ -17866,8 +17917,8 @@ xmlSchemaTypeFixupWhitespace(xmlSchemaTypePtr type)
        }
     }
     /*
-    * For all �atomic� datatypes other than string (and types �derived�
-    * by �restriction� from it) the value of whiteSpace is fixed to
+    * For all `atomic` datatypes other than string (and types `derived`
+    * by `restriction` from it) the value of whiteSpace is fixed to
     * collapse
     */
     {
@@ -18056,7 +18107,7 @@ xmlSchemaFixupSimpleTypeStageTwo(xmlSchemaParserCtxtPtr pctxt,
     * SPEC src-simple-type 1
     * "The corresponding simple type definition, if any, must satisfy
     * the conditions set out in Constraints on Simple Type Definition
-    * Schema Components (3.14.6)."
+    * Schema Components ($3.14.6)."
     */
     /*
     * Schema Component Constraint: Simple Type Definition Properties Correct
@@ -18316,7 +18367,7 @@ xmlSchemaFixupComplexType(xmlSchemaParserCtxtPtr pctxt,
            ( ((xmlSchemaTreeItemPtr) particle->children)->children == NULL))) {
            if (type->flags & XML_SCHEMAS_TYPE_MIXED) {
                /*
-               * SPEC (2.1.4) "If the �effective mixed� is true, then
+               * SPEC (2.1.4) "If the `effective mixed` is true, then
                * a particle whose properties are as follows:..."
                *
                * Empty sequence model group with
@@ -18378,7 +18429,7 @@ xmlSchemaFixupComplexType(xmlSchemaParserCtxtPtr pctxt,
            if (type->contentType == XML_SCHEMA_CONTENT_EMPTY) {
                /*
                * SPEC (3.2.1)
-               * "If the �effective content� is empty, then the
+               * "If the `effective content` is empty, then the
                *  {content type} of the [...] base ..."
                */
                type->contentType = baseType->contentType;
@@ -18485,7 +18536,7 @@ xmlSchemaFixupComplexType(xmlSchemaParserCtxtPtr pctxt,
                    particle->children =
                        ((xmlSchemaParticlePtr) baseType->subtypes)->children;
                    /*
-                   * SPEC "followed by the �effective content�."
+                   * SPEC "followed by the `effective content`."
                    */
                    particle->next = effectiveContent;
                    /*
@@ -18629,12 +18680,12 @@ xmlSchemaCheckFacet(xmlSchemaFacetPtr facet,
 
                /* 4.3.5.5 Constraints on enumeration Schema Components
                * Schema Component Constraint: enumeration valid restriction
-               * It is an �error� if any member of {value} is not in the
-               * �value space� of {base type definition}.
+               * It is an `error` if any member of {value} is not in the
+               * `value space` of {base type definition}.
                *
                * minInclusive, maxInclusive, minExclusive, maxExclusive:
-               * The value �must� be in the
-               * �value space� of the �base type�.
+               * The value `must` be in the
+               * `value space` of the `base type`.
                */
                /*
                * This function is intended to deliver a compiled value
@@ -19069,9 +19120,9 @@ xmlSchemaCheckAttrGroupCircular(xmlSchemaAttributeGroupPtr attrGr,
     * not be an <attributeGroup> with ref [attribute] which resolves
     * to the component corresponding to this <attributeGroup>. Indirect
     * circularity is also ruled out. That is, when QName resolution
-    * (Schema Document) (�3.15.3) is applied to a �QName� arising from
+    * (Schema Document) ($3.15.3) is applied to a `QName` arising from
     * any <attributeGroup>s with a ref [attribute] among the [children],
-    * it must not be the case that a �QName� is encountered at any depth
+    * it must not be the case that a `QName` is encountered at any depth
     * which resolves to the component corresponding to this <attributeGroup>.
     */
     if (attrGr->attrUses == NULL)
@@ -19328,8 +19379,8 @@ xmlSchemaCheckAGPropsCorrect(xmlSchemaParserCtxtPtr pctxt,
     * SPEC ag-props-correct
     * (1) "The values of the properties of an attribute group definition
     * must be as described in the property tableau in The Attribute
-    * Group Definition Schema Component (3.6.1), modulo the impact of
-    * Missing Sub-components (5.3);"
+    * Group Definition Schema Component ($3.6.1), modulo the impact of
+    * Missing Sub-components ($5.3);"
     */
 
     if ((attrGr->attrUses != NULL) &&
@@ -19463,8 +19514,8 @@ xmlSchemaCheckAttrPropsCorrect(xmlSchemaParserCtxtPtr pctxt,
     * SPEC a-props-correct (1)
     * "The values of the properties of an attribute declaration must
     * be as described in the property tableau in The Attribute
-    * Declaration Schema Component (3.2.1), modulo the impact of
-    * Missing Sub-components (5.3)."
+    * Declaration Schema Component ($3.2.1), modulo the impact of
+    * Missing Sub-components ($5.3)."
     */
 
     if (WXS_ATTR_TYPEDEF(attr) == NULL)
@@ -19492,9 +19543,9 @@ xmlSchemaCheckAttrPropsCorrect(xmlSchemaParserCtxtPtr pctxt,
        /*
        * SPEC a-props-correct (2)
        * "if there is a {value constraint}, the canonical lexical
-       * representation of its value must be �valid� with respect
-       * to the {type definition} as defined in String Valid (3.14.4)."
-       * TODO: Don't care about the *cononical* stuff here, this requirement
+       * representation of its value must be `valid` with respect
+       * to the {type definition} as defined in String Valid ($3.14.4)."
+       * TODO: Don't care about the *canonical* stuff here, this requirement
        * will be removed in WXS 1.1 anyway.
        */
        ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST pctxt,
@@ -19561,15 +19612,15 @@ xmlSchemaCheckElemPropsCorrect(xmlSchemaParserCtxtPtr pctxt,
     /*
     * SPEC (1) "The values of the properties of an element declaration
     * must be as described in the property tableau in The Element
-    * Declaration Schema Component (3.3.1), modulo the impact of Missing
-    * Sub-components (5.3)."
+    * Declaration Schema Component ($3.3.1), modulo the impact of Missing
+    * Sub-components ($5.3)."
     */
     if (WXS_SUBST_HEAD(elemDecl) != NULL) {
        xmlSchemaElementPtr head = WXS_SUBST_HEAD(elemDecl), circ;
 
        xmlSchemaCheckElementDeclComponent(head, pctxt);
        /*
-       * SPEC (3) "If there is a non-�absent� {substitution group
+       * SPEC (3) "If there is a non-`absent` {substitution group
        * affiliation}, then {scope} must be global."
        */
        if ((elemDecl->flags & XML_SCHEMAS_ELEM_GLOBAL) == 0) {
@@ -19613,9 +19664,9 @@ xmlSchemaCheckElemPropsCorrect(xmlSchemaParserCtxtPtr pctxt,
        * of the element declaration must be validly derived from the {type
        * definition} of the {substitution group affiliation}, given the value
        * of the {substitution group exclusions} of the {substitution group
-       * affiliation}, as defined in Type Derivation OK (Complex) (3.4.6)
+       * affiliation}, as defined in Type Derivation OK (Complex) ($3.4.6)
        * (if the {type definition} is complex) or as defined in
-       * Type Derivation OK (Simple) (3.14.6) (if the {type definition} is
+       * Type Derivation OK (Simple) ($3.14.6) (if the {type definition} is
        * simple)."
        *
        * NOTE: {substitution group exclusions} means the values of the
@@ -19679,9 +19730,9 @@ xmlSchemaCheckElemPropsCorrect(xmlSchemaParserCtxtPtr pctxt,
 
        /*
        * SPEC (2) "If there is a {value constraint}, the canonical lexical
-       * representation of its value must be �valid� with respect to the
+       * representation of its value must be `valid` with respect to the
        * {type definition} as defined in Element Default Valid (Immediate)
-       * (3.3.6)."
+       * ($3.3.6)."
        */
        if (typeDef == NULL) {
            xmlSchemaPErr(pctxt, elemDecl->node,
@@ -19749,7 +19800,7 @@ xmlSchemaCheckElemSubstGroup(xmlSchemaParserCtxtPtr ctxt,
        /*
        * SPEC (2) "It is validly substitutable for HEAD subject to HEAD's
        * {disallowed substitutions} as the blocking constraint, as defined in
-       * Substitution Group OK (Transitive) (3.3.6)."
+       * Substitution Group OK (Transitive) ($3.3.6)."
        */
        for (head = WXS_SUBST_HEAD(elemDecl); head != NULL;
            head = WXS_SUBST_HEAD(head)) {
@@ -19882,7 +19933,7 @@ xmlSchemaCheckElementDeclConsistent(xmlSchemaParserCtxtPtr pctxt,
                    * SPEC Element Declarations Consistent:
                    * "If the {particles} contains, either directly,
                    * indirectly (that is, within the {particles} of a
-                   * contained model group, recursively) or �implicitly�
+                   * contained model group, recursively) or `implicitly`
                    * two or more element declaration particles with
                    * the same {name} and {target namespace}, then
                    * all their type definitions must be the same
@@ -20080,12 +20131,12 @@ xmlSchemaAreValuesEqual(xmlSchemaValPtr x,
        ptx = xmlSchemaGetPrimitiveType(tx);
        pty = xmlSchemaGetPrimitiveType(ty);
        /*
-       * (1) if a datatype T' is �derived� by �restriction� from an
-       * atomic datatype T then the �value space� of T' is a subset of
-       * the �value space� of T. */
+       * (1) if a datatype T' is `derived` by `restriction` from an
+       * atomic datatype T then the `value space` of T' is a subset of
+       * the `value space` of T. */
        /*
-       * (2) if datatypes T' and T'' are �derived� by �restriction�
-       * from a common atomic ancestor T then the �value space�s of T'
+       * (2) if datatypes T' and T'' are `derived` by `restriction`
+       * from a common atomic ancestor T then the `value space`s of T'
        * and T'' may overlap.
        */
        if (ptx != pty)
@@ -20153,7 +20204,7 @@ xmlSchemaResolveAttrUseReferences(xmlSchemaAttributeUsePtr ause,
            ref->name, ref->targetNamespace);
         if (ause->attrDecl == NULL) {
            xmlSchemaPResCompAttrErr(ctxt,
-               XML_SCHEMAP_SRC_RESOLVE,
+               XML_SCHEMAP_SRC_RESOLVE,
                WXS_BASIC_CAST ause, ause->node,
                "ref", ref->name, ref->targetNamespace,
                XML_SCHEMA_TYPE_ATTRIBUTE, NULL);
@@ -20186,8 +20237,8 @@ xmlSchemaCheckAttrUsePropsCorrect(xmlSchemaParserCtxtPtr ctxt,
     * SPEC au-props-correct (1)
     * "The values of the properties of an attribute use must be as
     * described in the property tableau in The Attribute Use Schema
-    * Component (3.5.1), modulo the impact of Missing
-    * Sub-components (5.3)."
+    * Component ($3.5.1), modulo the impact of Missing
+    * Sub-components ($5.3)."
     */
 
     if (((WXS_ATTRUSE_DECL(use))->defValue != NULL) &&
@@ -20288,8 +20339,8 @@ xmlSchemaResolveAttrTypeReferences(xmlSchemaAttributePtr item,
     /*
     * The simple type definition corresponding to the <simpleType> element
     * information item in the [children], if present, otherwise the simple
-    * type definition �resolved� to by the �actual value� of the type
-    * [attribute], if present, otherwise the �simple ur-type definition�.
+    * type definition `resolved` to by the `actual value` of the type
+    * [attribute], if present, otherwise the `simple ur-type definition`.
     */
     if (item->flags & XML_SCHEMAS_ATTR_INTERNAL_RESOLVED)
        return(0);
@@ -20453,11 +20504,11 @@ xmlSchemaCheckSRCRedefineFirst(xmlSchemaParserCtxtPtr pctxt)
 
            /*
            * SPEC src-redefine:
-           * (6.2.1) "The �actual value� of its own name attribute plus
-           * target namespace must successfully �resolve� to a model
+           * (6.2.1) "The `actual value` of its own name attribute plus
+           * target namespace must successfully `resolve` to a model
            * group definition in I."
-           * (7.2.1) "The �actual value� of its own name attribute plus
-           * target namespace must successfully �resolve� to an attribute
+           * (7.2.1) "The `actual value` of its own name attribute plus
+           * target namespace must successfully `resolve` to an attribute
            * group definition in I."
 
            *
@@ -20630,10 +20681,10 @@ xmlSchemaCheckSRCRedefineSecond(xmlSchemaParserCtxtPtr pctxt)
                * SPEC src-redefine:
                * (6.2.2) "The {model group} of the model group definition
                * which corresponds to it per XML Representation of Model
-               * Group Definition Schema Components (3.7.2) must be a
-               * �valid restriction� of the {model group} of that model
+               * Group Definition Schema Components ($3.7.2) must be a
+               * `valid restriction` of the {model group} of that model
                * group definition in I, as defined in Particle Valid
-               * (Restriction) (3.9.6)."
+               * (Restriction) ($3.9.6)."
                */
                break;
            case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
@@ -20642,11 +20693,11 @@ xmlSchemaCheckSRCRedefineSecond(xmlSchemaParserCtxtPtr pctxt)
                * (7.2.2) "The {attribute uses} and {attribute wildcard} of
                * the attribute group definition which corresponds to it
                * per XML Representation of Attribute Group Definition Schema
-               * Components (�3.6.2) must be �valid restrictions� of the
+               * Components ($3.6.2) must be `valid restrictions` of the
                * {attribute uses} and {attribute wildcard} of that attribute
                * group definition in I, as defined in clause 2, clause 3 and
                * clause 4 of Derivation Valid (Restriction, Complex)
-               * (3.4.6) (where references to the base type definition are
+               * ($3.4.6) (where references to the base type definition are
                * understood as references to the attribute group definition
                * in I)."
                */
@@ -20821,9 +20872,9 @@ xmlSchemaFixupComponents(xmlSchemaParserCtxtPtr pctxt,
 
     * (6.2.2) The {model group} of the model group definition which
     * corresponds to it per XML Representation of Model Group
-    * Definition Schema Components (�3.7.2) must be a �valid
-    * restriction of the {model group} of that model group definition
-    * in I, as defined in Particle Valid (Restriction) (3.9.6)."
+    * Definition Schema Components ($3.7.2) must be a `valid
+    * restriction` of the {model group} of that model group definition
+    * in I, as defined in Particle Valid (Restriction) ($3.9.6)."
     */
     xmlSchemaCheckSRCRedefineFirst(pctxt);
 
@@ -21370,7 +21421,7 @@ exit_failure:
        ctxt->ownsConstructor = 0;
     }
     PERROR_INT2("xmlSchemaParse",
-       "An internal error occured");
+       "An internal error occurred");
     ctxt->schema = NULL;
     return(NULL);
 }
@@ -21507,8 +21558,8 @@ xmlSchemaGetWhiteSpaceFacetValue(xmlSchemaTypePtr type)
            return(XML_SCHEMA_WHITESPACE_REPLACE);
        else {
            /*
-           * For all �atomic� datatypes other than string (and types �derived�
-           * by �restriction� from it) the value of whiteSpace is fixed to
+           * For all `atomic` datatypes other than string (and types `derived`
+           * by `restriction` from it) the value of whiteSpace is fixed to
            * collapse
            * Note that this includes built-in list datatypes.
            */
@@ -21533,16 +21584,16 @@ xmlSchemaGetWhiteSpaceFacetValue(xmlSchemaTypePtr type)
 }
 
 /************************************************************************
- *                                                                     *
- *                     Simple type validation                          *
- *                                                                     *
+ *                                                                     *
+ *                     Simple type validation                          *
+ *                                                                     *
  ************************************************************************/
 
 
 /************************************************************************
- *                                                                     *
- *                     DOM Validation code                             *
- *                                                                     *
+ *                                                                     *
+ *                     DOM Validation code                             *
+ *                                                                     *
  ************************************************************************/
 
 /**
@@ -21936,9 +21987,9 @@ xmlSchemaVAddNodeQName(xmlSchemaValidCtxtPtr vctxt,
 }
 
 /************************************************************************
- *                                                                     *
+ *                                                                     *
  *  Validation of identity-constraints (IDC)                            *
- *                                                                     *
+ *                                                                     *
  ************************************************************************/
 
 /**
@@ -21986,7 +22037,7 @@ xmlSchemaAugmentIDC(xmlSchemaIDCPtr idcDef,
  * Creates an augmented IDC definition for the imported schema.
  */
 static void
-xmlSchemaAugmentImportedIDC(xmlSchemaImportPtr imported, xmlSchemaValidCtxtPtr vctxt) {
+xmlSchemaAugmentImportedIDC(xmlSchemaImportPtr imported, xmlSchemaValidCtxtPtr vctxt, xmlChar *name ATTRIBUTE_UNUSED) {
     if (imported->schema->idcDef != NULL) {
            xmlHashScan(imported->schema->idcDef ,
            (xmlHashScanner) xmlSchemaAugmentIDC, vctxt);
@@ -22813,7 +22864,7 @@ xmlSchemaXPathProcessHistory(xmlSchemaValidCtxtPtr vctxt,
                    xmlChar *str = NULL;
                    /*
                    * cvc-identity-constraint:
-                   * 3 For each node in the �target node set� all
+                   * 3 For each node in the `target node set` all
                    * of the {fields}, with that node as the context
                    * node, evaluate to either an empty node-set or
                    * a node-set with exactly one member, which must
@@ -22943,8 +22994,8 @@ create_key:
 
            /*
            * 4.1 If the {identity-constraint category} is unique(/key),
-           * then no two members of the �qualified node set� have
-           * �key-sequences� whose members are pairwise equal, as
+           * then no two members of the `qualified node set` have
+           * `key-sequences` whose members are pairwise equal, as
            * defined by Equal in [XML Schemas: Datatypes].
            *
            * Get the IDC binding from the matcher and check for
@@ -23072,10 +23123,10 @@ selector_key_error:
            {
                xmlChar *str = NULL;
                /*
-               * 4.2.1 (KEY) The �target node set� and the
-               * �qualified node set� are equal, that is, every
-               * member of the �target node set� is also a member
-               * of the �qualified node set� and vice versa.
+               * 4.2.1 (KEY) The `target node set` and the
+               * `qualified node set` are equal, that is, every
+               * member of the `target node set` is also a member
+               * of the `qualified node set` and vice versa.
                */
                xmlSchemaCustomErr(ACTXT_CAST vctxt,
                    XML_SCHEMAV_CVC_IDC, NULL,
@@ -23866,9 +23917,9 @@ xmlSchemaCheckCVCIDCKeyRef(xmlSchemaValidCtxtPtr vctxt)
 }
 
 /************************************************************************
- *                                                                     *
- *                     XML Reader validation code                      *
- *                                                                     *
+ *                                                                     *
+ *                     XML Reader validation code                      *
+ *                                                                     *
  ************************************************************************/
 
 static xmlSchemaAttrInfoPtr
@@ -24156,6 +24207,7 @@ xmlSchemaValidateFacets(xmlSchemaAbstractCtxtPtr actxt,
        else
            goto pattern_and_enum;
     }
+
     /*
     * Whitespace handling is only of importance for string-based
     * types.
@@ -24166,14 +24218,13 @@ xmlSchemaValidateFacets(xmlSchemaAbstractCtxtPtr actxt,
        ws = xmlSchemaGetWhiteSpaceFacetValue(type);
     } else
        ws = XML_SCHEMA_WHITESPACE_COLLAPSE;
+
     /*
     * If the value was not computed (for string or
     * anySimpleType based types), then use the provided
     * type.
     */
-    if (val == NULL)
-       valType = valType;
-    else
+    if (val != NULL)
        valType = xmlSchemaGetValType(val);
 
     ret = 0;
@@ -24471,14 +24522,14 @@ xmlSchemaVCheckCVCSimpleType(xmlSchemaAbstractCtxtPtr actxt,
     */
     /*
     * 2.1 If The definition is ENTITY or is validly derived from ENTITY given
-    * the empty set, as defined in Type Derivation OK (Simple) (3.14.6), then
-    * the string must be a �declared entity name�.
+    * the empty set, as defined in Type Derivation OK (Simple) ($3.14.6), then
+    * the string must be a `declared entity name`.
     */
     /*
     * 2.2 If The definition is ENTITIES or is validly derived from ENTITIES
-    * given the empty set, as defined in Type Derivation OK (Simple) (3.14.6),
-    * then every whitespace-delimited substring of the string must be a declared
-    * entity name.
+    * given the empty set, as defined in Type Derivation OK (Simple) ($3.14.6),
+    * then every whitespace-delimited substring of the string must be a `declared
+    * entity name`.
     */
     /*
     * 2.3 otherwise no further condition applies.
@@ -24490,8 +24541,8 @@ xmlSchemaVCheckCVCSimpleType(xmlSchemaAbstractCtxtPtr actxt,
     if (WXS_IS_ANY_SIMPLE_TYPE(type) || WXS_IS_ATOMIC(type)) {
        xmlSchemaTypePtr biType; /* The built-in type. */
        /*
-       * SPEC (1.2.1) "if {variety} is �atomic� then the string must �match�
-       * a literal in the �lexical space� of {base type definition}"
+       * SPEC (1.2.1) "if {variety} is `atomic` then the string must `match`
+       * a literal in the `lexical space` of {base type definition}"
        */
        /*
        * Whitespace-normalize.
@@ -24602,9 +24653,9 @@ xmlSchemaVCheckCVCSimpleType(xmlSchemaAbstractCtxtPtr actxt,
        xmlChar *tmpValue = NULL;
        unsigned long len = 0;
        xmlSchemaValPtr prevVal = NULL, curVal = NULL;
-       /* 1.2.2 if {variety} is �list� then the string must be a sequence
-       * of white space separated tokens, each of which �match�es a literal
-       * in the �lexical space� of {item type definition}
+       /* 1.2.2 if {variety} is `list` then the string must be a sequence
+       * of white space separated tokens, each of which `match`es a literal
+       * in the `lexical space` of {item type definition}
        */
        /*
        * Note that XML_SCHEMAS_TYPE_NORMVALUENEEDED will be set if
@@ -24685,10 +24736,10 @@ xmlSchemaVCheckCVCSimpleType(xmlSchemaAbstractCtxtPtr actxt,
     } else if (WXS_IS_UNION(type)) {
        xmlSchemaTypeLinkPtr memberLink;
        /*
-       * TODO: For all datatypes �derived� by �union�  whiteSpace does
-       * not apply directly; however, the normalization behavior of �union�
+       * TODO: For all datatypes `derived` by `union`  whiteSpace does
+       * not apply directly; however, the normalization behavior of `union`
        * types is controlled by the value of whiteSpace on that one of the
-       * �memberTypes� against which the �union� is successfully validated.
+       * `memberTypes` against which the `union` is successfully validated.
        *
        * This means that the value is normalized by the first validating
        * member type, then the facets of the union type are applied. This
@@ -24696,8 +24747,8 @@ xmlSchemaVCheckCVCSimpleType(xmlSchemaAbstractCtxtPtr actxt,
        */
 
        /*
-       * 1.2.3 if {variety} is �union� then the string must �match� a
-       * literal in the �lexical space� of at least one member of
+       * 1.2.3 if {variety} is `union` then the string must `match` a
+       * literal in the `lexical space` of at least one member of
        * {member type definitions}
        */
        memberLink = xmlSchemaGetUnionSimpleTypeMemberTypes(type);
@@ -24736,9 +24787,9 @@ xmlSchemaVCheckCVCSimpleType(xmlSchemaAbstractCtxtPtr actxt,
        */
        if ((ret == 0) && (type->flags & XML_SCHEMAS_TYPE_HAS_FACETS)) {
            /*
-           * The normalization behavior of �union� types is controlled by
-           * the value of whiteSpace on that one of the �memberTypes�
-           * against which the �union� is successfully validated.
+           * The normalization behavior of `union` types is controlled by
+           * the value of whiteSpace on that one of the `memberTypes`
+           * against which the `union` is successfully validated.
            */
            NORMALIZE(memberLink->type);
            ret = xmlSchemaValidateFacets(actxt, node, type,
@@ -24898,14 +24949,14 @@ xmlSchemaProcessXSIType(xmlSchemaValidCtxtPtr vctxt,
 
            /*
            * SPEC cvc-elt (3.3.4) : (4.3) (Type Derivation OK)
-           * "The �local type definition� must be validly
+           * "The `local type definition` must be validly
            * derived from the {type definition} given the union of
            * the {disallowed substitutions} and the {type definition}'s
            * {prohibited substitutions}, as defined in
-           * Type Derivation OK (Complex) (3.4.6)
+           * Type Derivation OK (Complex) ($3.4.6)
            * (if it is a complex type definition),
            * or given {disallowed substitutions} as defined in Type
-           * Derivation OK (Simple) (3.14.6) (if it is a simple type
+           * Derivation OK (Simple) ($3.14.6) (if it is a simple type
            * definition)."
            *
            * {disallowed substitutions}: the "block" on the element decl.
@@ -24988,9 +25039,9 @@ xmlSchemaValidateElemDecl(xmlSchemaValidCtxtPtr vctxt)
         return (vctxt->err);
     }
     if (actualType == NULL) {
-       VERROR(XML_SCHEMAV_CVC_TYPE_1, NULL,
-           "The type definition is absent");
-       return (XML_SCHEMAV_CVC_TYPE_1);
+       VERROR(XML_SCHEMAV_CVC_TYPE_1, NULL,
+           "The type definition is absent");
+       return (XML_SCHEMAV_CVC_TYPE_1);
     }
     if (vctxt->nbAttrInfos != 0) {
        int ret;
@@ -25080,9 +25131,9 @@ xmlSchemaValidateElemDecl(xmlSchemaValidCtxtPtr vctxt)
     * No actual type definition.
     */
     if (actualType == NULL) {
-       VERROR(XML_SCHEMAV_CVC_TYPE_1, NULL,
-           "The type definition is absent");
-       return (XML_SCHEMAV_CVC_TYPE_1);
+       VERROR(XML_SCHEMAV_CVC_TYPE_1, NULL,
+           "The type definition is absent");
+       return (XML_SCHEMAV_CVC_TYPE_1);
     }
     /*
     * Remember the actual type definition.
@@ -25176,8 +25227,8 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
 
     /*
     * SPEC (cvc-attribute)
-    * (1) "The declaration must not be �absent� (see Missing
-    * Sub-components (5.3) for how this can fail to be
+    * (1) "The declaration must not be `absent` (see Missing
+    * Sub-components ($5.3) for how this can fail to be
     * the case)."
     * (2) "Its {type definition} must not be absent."
     *
@@ -25227,15 +25278,15 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
            * use with an {attribute declaration} whose {name} matches
            * the attribute information item's [local name] and whose
            * {target namespace} is identical to the attribute information
-           * item's [namespace name] (where an �absent� {target namespace}
+           * item's [namespace name] (where an `absent` {target namespace}
            * is taken to be identical to a [namespace name] with no value),
-           * then the attribute information must be �valid� with respect
+           * then the attribute information must be `valid` with respect
            * to that attribute use as per Attribute Locally Valid (Use)
-           * (3.5.4). In this case the {attribute declaration} of that
-           * attribute use is the �context-determined declaration� for the
+           * ($3.5.4). In this case the {attribute declaration} of that
+           * attribute use is the `context-determined declaration` for the
            * attribute information item with respect to Schema-Validity
-           * Assessment (Attribute) (3.2.4) and
-           * Assessment Outcome (Attribute) (3.2.5).
+           * Assessment (Attribute) ($3.2.4) and
+           * Assessment Outcome (Attribute) ($3.2.5).
            */
            iattr->state = XML_SCHEMAS_ATTR_ASSESSED;
            iattr->use = attrUse;
@@ -25312,13 +25363,13 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
                continue;
            /*
            * SPEC (cvc-complex-type)
-           * (3.2.2) "The attribute information item must be �valid� with
-           * respect to it as defined in Item Valid (Wildcard) (3.10.4)."
+           * (3.2.2) "The attribute information item must be `valid` with
+           * respect to it as defined in Item Valid (Wildcard) ($3.10.4)."
            *
            * SPEC Item Valid (Wildcard) (cvc-wildcard)
-           * "... its [namespace name] must be �valid� with respect to
+           * "... its [namespace name] must be `valid` with respect to
            * the wildcard constraint, as defined in Wildcard allows
-           * Namespace Name (3.10.4)."
+           * Namespace Name ($3.10.4)."
            */
            if (xmlSchemaCheckCVCWildcardNamespace(type->attributeWildcard,
                    iattr->nsName) == 0) {
@@ -25354,11 +25405,11 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
                    * SPEC (cvc-complex-type)
                    * (5) "Let [Definition:]  the wild IDs be the set of
                    * all attribute information item to which clause 3.2
-                   * applied and whose �validation� resulted in a
-                   * �context-determined declaration� of mustFind or no
-                   * �context-determined declaration� at all, and whose
+                   * applied and whose `validation` resulted in a
+                   * `context-determined declaration` of mustFind or no
+                   * `context-determined declaration` at all, and whose
                    * [local name] and [namespace name] resolve (as
-                   * defined by QName resolution (Instance) (3.15.4)) to
+                   * defined by QName resolution (Instance) ($3.15.4)) to
                    * an attribute declaration whose {type definition} is
                    * or is derived from ID. Then all of the following
                    * must be true:"
@@ -25368,7 +25419,7 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
                        iattr->typeDef, XML_SCHEMAS_ID)) {
                        /*
                        * SPEC (5.1) "There must be no more than one
-                       * item in �wild IDs�."
+                       * item in `wild IDs`."
                        */
                        if (wildIDs != 0) {
                            /* VAL TODO */
@@ -25379,7 +25430,7 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
                        wildIDs++;
                        /*
                        * SPEC (cvc-complex-type)
-                       * (5.2) "If �wild IDs� is non-empty, there must not
+                       * (5.2) "If `wild IDs` is non-empty, there must not
                        * be any attribute uses among the {attribute uses}
                        * whose {attribute declaration}'s {type definition}
                        * is or is derived from ID."
@@ -25516,7 +25567,7 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
                    if (xmlNewProp(defAttrOwnerElem,
                        iattr->localName, value) == NULL) {
                        VERROR_INT("xmlSchemaVAttributesComplex",
-                           "callling xmlNewProp()");
+                           "calling xmlNewProp()");
                        if (normValue != NULL)
                            xmlFree(normValue);
                        goto internal_error;
@@ -25589,9 +25640,9 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
            fixed = 0;
        /*
        * SPEC (cvc-attribute)
-       * (3) "The item's �normalized value� must be locally �valid�
+       * (3) "The item's `normalized value` must be locally `valid`
        * with respect to that {type definition} as per
-       * String Valid (3.14.4)."
+       * String Valid ($3.14.4)."
        *
        * VAL TODO: Do we already have the
        * "normalized attribute value" here?
@@ -25629,9 +25680,9 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
        if (fixed) {
            /*
            * SPEC Attribute Locally Valid (Use) (cvc-au)
-           * "For an attribute information item to be�valid�
+           * "For an attribute information item to be `valid`
            * with respect to an attribute use its *normalized*
-           * value must match the *canonical* lexical
+           * value must match the *canonical* lexical
            * representation of the attribute use's {value
            * constraint}value, if it is present and fixed."
            *
@@ -25640,7 +25691,7 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
            */
            /*
            * SPEC Attribute Locally Valid (cvc-attribute)
-           * (4) "The item's *actual* value must match the *value* of
+           * (4) "The item's *actual* value must match the *value* of
            * the {value constraint}, if it is present and fixed."
            */
            if (iattr->val == NULL) {
@@ -25870,8 +25921,8 @@ xmlSchemaCheckCOSValidDefault(xmlSchemaValidCtxtPtr vctxt,
        * SPEC (2.1) "its {content type} must be a simple type definition
        * or mixed."
        * SPEC (2.2.2) "If the {content type} is mixed, then the {content
-       * type}'s particle must be �emptiable� as defined by
-       * Particle Emptiable (3.9.6)."
+       * type}'s particle must be `emptiable` as defined by
+       * Particle Emptiable ($3.9.6)."
        */
        if ((! WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) &&
            ((! WXS_HAS_MIXED_CONTENT(inode->typeDef)) ||
@@ -25887,14 +25938,14 @@ xmlSchemaCheckCOSValidDefault(xmlSchemaValidCtxtPtr vctxt,
     }
     /*
     * 1 If the type definition is a simple type definition, then the string
-    * must be �valid� with respect to that definition as defined by String
-    * Valid (3.14.4).
+    * must be `valid` with respect to that definition as defined by String
+    * Valid ($3.14.4).
     *
     * AND
     *
     * 2.2.1 If the {content type} is a simple type definition, then the
-    * string must be �valid� with respect to that simple type definition
-    * as defined by String Valid (3.14.4).
+    * string must be `valid` with respect to that simple type definition
+    * as defined by String Valid ($3.14.4).
     */
     if (WXS_IS_SIMPLE(inode->typeDef)) {
 
@@ -26035,9 +26086,23 @@ xmlSchemaValidatorPopElem(xmlSchemaValidCtxtPtr vctxt)
                    "AUTOMATON create on '%s'\n", inode->localName);
 #endif
            }
+
+           /*
+            * Do not check further content if the node has been nilled
+            */
+           if (INODE_NILLED(inode)) {
+               ret = 0;
+#ifdef DEBUG_AUTOMATA
+               xmlGenericError(xmlGenericErrorContext,
+                   "AUTOMATON succeeded on nilled '%s'\n",
+                   inode->localName);
+#endif
+                goto skip_nilled;
+           }
+
            /*
            * Get hold of the still expected content, since a further
-           * call to xmlRegExecPushString() will loose this information.
+           * call to xmlRegExecPushString() will lose this information.
            */
            xmlRegExecNextValues(inode->regexCtxt,
                &nbval, &nbneg, &values[0], &terminal);
@@ -26072,6 +26137,9 @@ xmlSchemaValidatorPopElem(xmlSchemaValidCtxtPtr vctxt)
 
        }
     }
+
+skip_nilled:
+
     if (inode->typeDef->contentType == XML_SCHEMA_CONTENT_ELEMENTS)
        goto end_elem;
 
@@ -26118,10 +26186,10 @@ character_content:
        (! INODE_NILLED(inode))) {
        /*
        * cvc-elt (3.3.4) : 5.1.1
-       * If the �actual type definition� is a �local type definition�
+       * If the `actual type definition` is a `local type definition`
        * then the canonical lexical representation of the {value constraint}
-       * value must be a valid default for the �actual type definition� as
-       * defined in Element Default Valid (Immediate) (3.3.6).
+       * value must be a valid default for the `actual type definition` as
+       * defined in Element Default Valid (Immediate) ($3.3.6).
        */
        /*
        * NOTE: 'local' above means types acquired by xsi:type.
@@ -26151,9 +26219,9 @@ character_content:
        * cvc-elt (3.3.4) : 5.1.2
        * The element information item with the canonical lexical
        * representation of the {value constraint} value used as its
-       * �normalized value� must be �valid� with respect to the
-       * �actual type definition� as defined by Element Locally Valid (Type)
-       * (3.3.4).
+       * `normalized value` must be `valid` with respect to the
+       * `actual type definition` as defined by Element Locally Valid (Type)
+       * ($3.3.4).
        */
        if (WXS_IS_SIMPLE(inode->typeDef)) {
            ret = xmlSchemaVCheckINodeDataType(vctxt,
@@ -26200,18 +26268,18 @@ default_psvi:
 
     } else if (! INODE_NILLED(inode)) {
        /*
-       * 5.2.1 The element information item must be �valid� with respect
-       * to the �actual type definition� as defined by Element Locally
-       * Valid (Type) (3.3.4).
+       * 5.2.1 The element information item must be `valid` with respect
+       * to the `actual type definition` as defined by Element Locally
+       * Valid (Type) ($3.3.4).
        */
        if (WXS_IS_SIMPLE(inode->typeDef)) {
             /*
            * SPEC (cvc-type) (3.1)
            * "If the type definition is a simple type definition, ..."
            * (3.1.3) "If clause 3.2 of Element Locally Valid
-           * (Element) (�3.3.4) did not apply, then the �normalized value�
-           * must be �valid� with respect to the type definition as defined
-           * by String Valid (3.14.4).
+           * (Element) ($3.3.4) did not apply, then the `normalized value`
+           * must be `valid` with respect to the type definition as defined
+           * by String Valid ($3.14.4).
            */
            ret = xmlSchemaVCheckINodeDataType(vctxt,
                    inode, inode->typeDef, inode->value);
@@ -26219,14 +26287,14 @@ default_psvi:
            /*
            * SPEC (cvc-type) (3.2) "If the type definition is a complex type
            * definition, then the element information item must be
-           * �valid� with respect to the type definition as per
-           * Element Locally Valid (Complex Type) (3.4.4);"
+           * `valid` with respect to the type definition as per
+           * Element Locally Valid (Complex Type) ($3.4.4);"
            *
            * SPEC (cvc-complex-type) (2.2)
            * "If the {content type} is a simple type definition, ...
-           * the �normalized value� of the element information item is
-           * �valid� with respect to that simple type definition as
-           * defined by String Valid (3.14.4)."
+           * the `normalized value` of the element information item is
+           * `valid` with respect to that simple type definition as
+           * defined by String Valid ($3.14.4)."
            */
            ret = xmlSchemaVCheckINodeDataType(vctxt,
                inode, inode->typeDef->contentTypeDef, inode->value);
@@ -26268,8 +26336,8 @@ default_psvi:
                */
                if (WXS_HAS_MIXED_CONTENT(inode->typeDef)) {
                    /*
-                   * 5.2.2.2.1 If the {content type} of the actual type
-                   * definition is mixed, then the *initial value* of the
+                   * 5.2.2.2.1 If the {content type} of the `actual type
+                   * definition` is mixed, then the *initial value* of the
                    * item must match the canonical lexical representation
                    * of the {value constraint} value.
                    *
@@ -26293,8 +26361,8 @@ default_psvi:
                    }
                } else if (WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) {
                    /*
-                   * 5.2.2.2.2 If the {content type} of the actual type
-                   * definition is a simple type definition, then the
+                   * 5.2.2.2.2 If the {content type} of the `actual type
+                   * definition` is a simple type definition, then the
                    * *actual value* of the item must match the canonical
                    * lexical representation of the {value constraint} value.
                    */
@@ -26335,9 +26403,9 @@ end_elem:
        goto internal_error;
     /*
     * MAYBE TODO:
-    * SPEC (6) "The element information item must be �valid� with
+    * SPEC (6) "The element information item must be `valid` with
     * respect to each of the {identity-constraint definitions} as per
-    * Identity-constraint Satisfied (3.11.4)."
+    * Identity-constraint Satisfied ($3.11.4)."
     */
     /*
     * PSVI TODO: If we expose IDC node-tables via PSVI then the tables
@@ -26415,8 +26483,8 @@ end_elem:
     vctxt->depth--;
     vctxt->inode = vctxt->elemInfos[vctxt->depth];
     /*
-    * VAL TODO: 7 If the element information item is the �validation root�, it must be
-    * �valid� per Validation Root Valid (ID/IDREF) (�3.3.4).
+    * VAL TODO: 7 If the element information item is the `validation root`, it must be
+    * `valid` per Validation Root Valid (ID/IDREF) ($3.3.4).
     */
     return (ret);
 
@@ -26497,11 +26565,11 @@ xmlSchemaValidateChildElem(xmlSchemaValidCtxtPtr vctxt)
                 * Fallback to "anyType".
                 *
                 * SPEC (cvc-assess-elt)
-                * "If the item cannot be �strictly assessed�, [...]
+                * "If the item cannot be `strictly assessed`, [...]
                 * an element information item's schema validity may be laxly
-                * assessed if its �context-determined declaration� is not
-                * skip by �validating� with respect to the �ur-type
-                * definition� as per Element Locally Valid (Type) (�3.3.4)."
+                * assessed if its `context-determined declaration` is not
+                * skip by `validating` with respect to the `ur-type
+                * definition` as per Element Locally Valid (Type) ($3.3.4)."
                */
                vctxt->inode->typeDef =
                    xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE);
@@ -26573,9 +26641,9 @@ xmlSchemaValidateChildElem(xmlSchemaValidCtxtPtr vctxt)
            * SPEC (2.4) "If the {content type} is element-only or mixed,
            * then the sequence of the element information item's
            * element information item [children], if any, taken in
-           * order, is �valid� with respect to the {content type}'s
+           * order, is `valid` with respect to the {content type}'s
            * particle, as defined in Element Sequence Locally Valid
-           * (Particle) (3.9.4)."
+           * (Particle) ($3.9.4)."
            */
            ret = xmlRegExecPushString2(regexCtxt,
                vctxt->inode->localName,
@@ -26910,15 +26978,15 @@ type_validation:
     if (vctxt->inode->typeDef == NULL) {
        vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE;
        ret = XML_SCHEMAV_CVC_TYPE_1;
-       VERROR(ret, NULL,
-           "The type definition is absent");
+       VERROR(ret, NULL,
+           "The type definition is absent");
        goto exit;
     }
     if (vctxt->inode->typeDef->flags & XML_SCHEMAS_TYPE_ABSTRACT) {
        vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE;
        ret = XML_SCHEMAV_CVC_TYPE_2;
-           VERROR(ret, NULL,
-           "The type definition is abstract");
+           VERROR(ret, NULL,
+           "The type definition is abstract");
        goto exit;
     }
     /*
@@ -27090,7 +27158,7 @@ root_found:
                    }
                    if (ret < 0) {
                        /*
-                       * VAL TODO: A reader error occured; what to do here?
+                       * VAL TODO: A reader error occurred; what to do here?
                        */
                        ret = 1;
                        goto exit;
@@ -27165,9 +27233,9 @@ internal_error:
 #endif
 
 /************************************************************************
- *                                                                     *
- *                     SAX validation handlers                         *
- *                                                                     *
+ *                                                                     *
+ *                     SAX validation handlers                         *
+ *                                                                     *
  ************************************************************************/
 
 /*
@@ -27331,14 +27399,41 @@ xmlSchemaSAXHandleStartElementNs(void *ctx,
     * attributes yet.
     */
     if (nb_attributes != 0) {
+       int valueLen, k, l;
        xmlChar *value;
 
         for (j = 0, i = 0; i < nb_attributes; i++, j += 5) {
            /*
-           * Duplicate the value.
+           * Duplicate the value, changing any &#38; to a literal ampersand.
+           *
+           * libxml2 differs from normal SAX here in that it escapes all ampersands
+           * as &#38; instead of delivering the raw converted string. Changing the
+           * behavior at this point would break applications that use this API, so
+           * we are forced to work around it.
            */
-           value = xmlStrndup(attributes[j+3],
-               attributes[j+4] - attributes[j+3]);
+           valueLen = attributes[j+4] - attributes[j+3];
+           value = xmlMallocAtomic(valueLen + 1);
+           if (value == NULL) {
+               xmlSchemaVErrMemory(vctxt,
+                   "allocating string for decoded attribute",
+                   NULL);
+               goto internal_error;
+           }
+           for (k = 0, l = 0; k < valueLen; l++) {
+               if (k < valueLen - 4 &&
+                   attributes[j+3][k+0] == '&' &&
+                   attributes[j+3][k+1] == '#' &&
+                   attributes[j+3][k+2] == '3' &&
+                   attributes[j+3][k+3] == '8' &&
+                   attributes[j+3][k+4] == ';') {
+                   value[l] = '&';
+                   k += 5;
+               } else {
+                   value[l] = attributes[j+3][k];
+                   k++;
+               }
+           }
+           value[l] = '\0';
            /*
            * TODO: Set the node line.
            */
@@ -27418,9 +27513,9 @@ internal_error:
 }
 
 /************************************************************************
- *                                                                     *
- *                     Validation interfaces                           *
- *                                                                     *
+ *                                                                     *
+ *                     Validation interfaces                           *
+ *                                                                     *
  ************************************************************************/
 
 /**
@@ -27450,8 +27545,28 @@ xmlSchemaNewValidCtxt(xmlSchemaPtr schema)
 }
 
 /**
+ * xmlSchemaValidateSetFilename:
+ * @vctxt: the schema validation context
+ * @filename: the file name
+ *
+ * Workaround to provide file error reporting information when this is
+ * not provided by current APIs
+ */
+void
+xmlSchemaValidateSetFilename(xmlSchemaValidCtxtPtr vctxt, const char *filename) {
+    if (vctxt == NULL)
+        return;
+    if (vctxt->filename != NULL)
+        xmlFree(vctxt->filename);
+    if (filename != NULL)
+        vctxt->filename = (char *) xmlStrdup((const xmlChar *) filename);
+    else
+        vctxt->filename = NULL;
+}
+
+/**
  * xmlSchemaClearValidCtxt:
- * @ctxt: the schema validation context
+ * @vctxt: the schema validation context
  *
  * Free the resources associated to the schema validation context;
  * leaves some fields alive intended for reuse of the context.
@@ -27552,6 +27667,11 @@ xmlSchemaClearValidCtxt(xmlSchemaValidCtxtPtr vctxt)
     * where the user provides the dict?
     */
     vctxt->dict = xmlDictCreate();
+
+    if (vctxt->filename != NULL) {
+        xmlFree(vctxt->filename);
+       vctxt->filename = NULL;
+    }
 }
 
 /**
@@ -27637,6 +27757,8 @@ xmlSchemaFreeValidCtxt(xmlSchemaValidCtxtPtr ctxt)
        xmlSchemaItemListFree(ctxt->nodeQNames);
     if (ctxt->dict != NULL)
        xmlDictFree(ctxt->dict);
+    if (ctxt->filename != NULL)
+       xmlFree(ctxt->filename);
     xmlFree(ctxt);
 }
 
@@ -27791,7 +27913,10 @@ xmlSchemaVDocWalk(xmlSchemaValidCtxtPtr vctxt)
     const xmlChar *nsName;
 
     /* DOC VAL TODO: Move this to the start function. */
-    valRoot = xmlDocGetRootElement(vctxt->doc);
+    if (vctxt->validationRoot != NULL)
+        valRoot = vctxt->validationRoot;
+    else
+       valRoot = xmlDocGetRootElement(vctxt->doc);
     if (valRoot == NULL) {
        /* VAL TODO: Error code? */
        VERROR(1, NULL, "The document has no document element");
@@ -28112,9 +28237,9 @@ xmlSchemaValidateDoc(xmlSchemaValidCtxtPtr ctxt, xmlDocPtr doc)
 
 
 /************************************************************************
- *                                                                     *
- *             Function and data for SAX streaming API                 *
- *                                                                     *
+ *                                                                     *
+ *             Function and data for SAX streaming API                 *
+ *                                                                     *
  ************************************************************************/
 typedef struct _xmlSchemaSplitSAXData xmlSchemaSplitSAXData;
 typedef xmlSchemaSplitSAXData *xmlSchemaSplitSAXDataPtr;
@@ -28631,6 +28756,63 @@ xmlSchemaSAXUnplug(xmlSchemaSAXPlugPtr plug)
 }
 
 /**
+ * xmlSchemaValidateSetLocator:
+ * @vctxt: a schema validation context
+ * @f: the locator function pointer
+ * @ctxt: the locator context
+ *
+ * Allows to set a locator function to the validation context,
+ * which will be used to provide file and line information since
+ * those are not provided as part of the SAX validation flow
+ * Setting @f to NULL disable the locator.
+ */
+
+void
+xmlSchemaValidateSetLocator(xmlSchemaValidCtxtPtr vctxt,
+                            xmlSchemaValidityLocatorFunc f,
+                           void *ctxt)
+{
+    if (vctxt == NULL) return;
+    vctxt->locFunc = f;
+    vctxt->locCtxt = ctxt;
+}
+
+/**
+ * xmlSchemaValidateStreamLocator:
+ * @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
+xmlSchemaValidateStreamLocator(void *ctx, const char **file,
+                               unsigned long *line) {
+    xmlParserCtxtPtr ctxt;
+
+    if ((ctx == NULL) || ((file == NULL) && (line == NULL)))
+        return(-1);
+
+    if (file != NULL)
+        *file = NULL;
+    if (line != NULL)
+        *line = 0;
+
+    ctxt = (xmlParserCtxtPtr) ctx;
+    if (ctxt->input != NULL) {
+       if (file != NULL)
+           *file = ctxt->input->filename;
+       if (line != NULL)
+           *line = ctxt->input->line;
+       return(0);
+    }
+    return(-1);
+}
+
+/**
  * xmlSchemaValidateStream:
  * @ctxt:  a schema validation context
  * @input:  the input to use for reading the data
@@ -28673,6 +28855,7 @@ xmlSchemaValidateStream(xmlSchemaValidCtxtPtr ctxt,
         xmlCtxtUseOptions(pctxt, options);
 #endif
     pctxt->linenumbers = 1;
+    xmlSchemaValidateSetLocator(ctxt, xmlSchemaValidateStreamLocator, pctxt);
 
     inputStream = xmlNewIOInputStream(pctxt, input, enc);;
     if (inputStream == NULL) {