- 我使用 Windows 和 MSXML 库 (msxml6.dll)。
- 我也在当前主题中使用 JS 作为示例。
- 如何针对 XMLSchema.xsd 验证我自己的方案(XSD 文件)?
- 在下面的示例代码中有关于我遇到的问题的评论。
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...
}