title: Validating XML that doesn't define a schema using Xerces
body: <p>I'm using the Xerces-C++ (version 2.6.1) SAX2 parser to validate XML such as the document below.  (This is MSML - Media Server Markup Language as defined in <a href="https://www.rfc-editor.org/rfc/rfc5707" rel="nofollow noreferrer">RFC 5707</a>.)</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;msml version=&quot;1.1&quot;&gt;
     &lt;createconference name=&quot;example&quot;&gt;
        &lt;audiomix&gt;
           &lt;n-loudest n=&quot;3&quot;/&gt;
           &lt;asn ri=&quot;10s&quot;/&gt;
        &lt;/audiomix&gt;
     &lt;/createconference&gt;
  &lt;/msml&gt;
  </code></pre>
  <p>The RFC provides <a href="https://www.rfc-editor.org/rfc/rfc5707#section-16" rel="nofollow noreferrer">XML schemas for validating MSML</a>, and I'm trying to use them in conjunction with the Xerces SAX2 parser to validate and parse MSML.  The parsing is working fine, but I'm failing to get any validation.  I suspect my problem might be because the MSML I'm trying to validate doesn't include a <code>schemaLocation</code> attribute, but I can't control what XML I receive - I would like to force validation using the msml.xsd whether <code>schemaLocation</code> or <code>noNamespaceSchemaLocation</code> (or nothing) is provided in the XML.</p>
  <p>My code is similar to the following.</p>
  <pre><code>SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
  
  // Enable the parser's schema support 
  parser-&gt;setFeature(XMLUni::fgXercesSchema, true);
  
  // Schema validation requires namespace processing to be turned on.
  parser-&gt;setFeature(XMLUni::fgSAX2CoreValidation, true);
  parser-&gt;setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
  
  // Define the location of the MSML schema.
  XMLCh* schemaLocation = XMLString::transcode(&quot;/directory/path/msml-core.xsd&quot;);
  parser-&gt;setProperty(XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation,
                      schemaLocation);
  
  // MSMLHandler is defined elsewhere and inherits from xercesc/sax2/DefaultHandler
  // It overrides startElement and fatalError.
  MxMSMLHandler* msmlHandler = new MSMLHandler(xiSessionID, xoMSMLResponse);
  parser-&gt;setContentHandler((ContentHandler*) msmlHandler);
  parser-&gt;setErrorHandler((ErrorHandler*) msmlHandler);
  
  // Do the parse
  parser-&gt;parse(*xmlInputSource);
  </code></pre>