xmlxsdxsd-validationmsxmlxml-schema-collection

How to validate my own Schema XSD file againts XMLSchema.xsd using MSXML?


  1. I use Windows and MSXML library (msxml6.dll).
  2. Also I use JS for the example in current topic.
  3. How can I validate my own Schems (XSD-file) against XMLSchema.xsd?
  4. In the sample code below there is the comment about problem I have.
var xs, xd;

main();

function main() 
{
  try {
    xs = new ActiveXObject("MSXML2.XMLSchemaCache.6.0");
    xd = new ActiveXObject("MSXML2.DOMDocument.6.0");
  }
  catch (e) {
    WScript.Echo("Mirosoft XML Core Services (MSXML) 6.0 is not installed.\n"
          +"Download and install MSXML 6.0 from http://msdn.microsoft.com/xml\n"
          +"before continuing.");
    return;
  }

  try {
    xd.async = false;
    xd.validateOnParse = false;
    xd.setProperty('ResolveExternals', false);
    xd.setProperty('ProhibitDTD', false);
    xd.setProperty('UseInlineSchema', false);
    xd.setProperty('MultipleErrorMessages', true);
    xd.load("e:\\Temp\\__SuperTemp\\XMLSchema.xsd") // just loaded from here http://www.w3.org/2001/XMLSchema.xsd
  }
  catch (e) {
    WScript.Echo("Failed to load schema cache: "+e.description);
    return;
  }

  if (xd.parseError.errorCode != 0) {
     WScript.Echo("Failed to parse schema cache: "+xd.parseError.reason);
    return;
  }

  try {
    // Here the error occured:
    //    XMLSchema.xsd#/schema/element[1][@name = 'schema']/complexType[1]/complexContent[1]/extension[1]/attribute[8]
    //    The 'http://www.w3.org/XML/1998/namespace:lang' attribute is not declared.
    // I really dont know what to do around it :((

    xs.add("http://www.w3.org/2001/XMLSchema", xd);
  }
  catch (e) {
    WScript.Echo("Failed to add schema cache: "+e.description);
    return;
  }

  // Next I wanted to validate my own XSD against XMLSchema.xsd.
  // But the error above occured. Soo, the further code is skipped...

}

Solution

  • Firstly, the W3C schema for schema documents (S4SD) does some things that would not be allowed in a user schema, like defining new primitive types, so there's no guarantee that every schema processor will consider it to be a valid schema. I've no idea if there are problems with MSXML (though it is rather old and venerable...)

    The specific problem you're having seems to be that S4SD imports the schema for the XML namespace

    and you seem to be picking up a version of that schema that doesn't declare xml:lang. I don't know why that should be happening; it might be worth putting in some kind of monitoring to see if the schema for the XML namespace is actually being loaded from that location. Perhaps MSXML has a "built-in" version of the schema for the XML namespace that doesn't include this attribute? But I would have thought that would break too much for it to be possible.

    I know this isn't a full resolution but I hope it takes you forward.