下面是我写的代码:
const request = require('request');
const libXMLJS = require("libxmljs");
request.get('https://www.w3.org/2009/XMLSchema/XMLSchema.xsd', function (error, response, body) {
if (!error && response.statusCode === 200) {
// is it well-formed?
try {
libXMLJS.parseXml(body);
} catch(e) {
console.log('schema schema not well-formed');
return;
}
console.log('schema schema well-formed');
// Is the schema schema a valid schema?
const schemaSchema = libXMLJS.parseXml(body);
try {
schemaSchema.validate(schemaSchema)
} catch(e) {
console.log('schema schema not valid schema');
return;
}
console.log('schema schema valid schema');
}
});输出结果为:
架构架构格式良好
架构架构不是有效的架构
这对我来说没什么意义。
发布于 2020-08-10 16:22:31
为什么要忽略exception e中的信息?如果你不看错误信息,你不知道它失败的原因也就不足为奇了。
话虽如此,https://www.w3.org/2009/XMLSchema/XMLSchema.xsd的模式文档似乎是XSD1.1的模式(尽管可能不是最终的模式,因为XSD1.1推荐标准是在2012年发布的),而libXML处理器只支持XSD1.0。
(我不知道用于Node.js的XSD1.1处理器。也许有一天我们会在Saxon-JS产品中包含模式处理,但它还没有实现。)
https://stackoverflow.com/questions/63333798
复制相似问题