3

I have an XML schema that I'm validating against using Xerces-C++ 3.1.1. My XML documents validate normally. I can cause a validation failure by renaming an element, or a required attribute, so I'm pretty sure Xerces is doing the right thing with the schema.

However, the documents still validate if I add unknown attributes to an arbitrary element. I want validation to fail if there are any undefined attributes, but the XML Schema spec and Xerces documentation are not making it clear how to do this.

Here's my xerces parser setup:

parser.setErrorHandler(&errorHandler);
parser.loadGrammar(schemaPath.c_str(), Grammar::SchemaGrammarType);
parser.setDoNamespaces(true);
parser.setDoSchema(true);
parser.setValidationConstraintFatal(true);
parser.setValidationSchemaFullChecking(true);

The schema and documents don't use namespaces, and I'm not using attribute wildcards.

Here's a toy schema and document demonstrating the issue; this is the same as the top-level element in the actual schema.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qual\
ified">
  <xs:element name="Document">
    <xs:complexType>
      <xs:attribute name="version"/>
    </xs:complexType>
  </xs:element>
</xs:schema>

This document validates against this schema, in spite of the unknown value attribute:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Document value="blar" version="22"/>

I want validation to fail when there's an attribute present that's not in the schema, like this case.

UltraNurd
  • 1,314
  • 2
  • 14
  • 24

0 Answers0