【发布时间】:2020-11-29 16:19:38
【问题描述】:
这是我写的代码:
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');
}
});
输出是:
模式模式格式良好
架构架构无效的架构
这对我来说没有意义。
【问题讨论】:
-
你捕捉到异常然后返回。这就是为什么。
-
这表明架构模式不够有效,无法验证自身。
-
在 Micheal Kay 的建议下,我改用 w3.org/2001/XMLSchema.xsd 而不是 w3.org/2009/XMLSchema/XMLSchema.xsd。仍然没有工作。 e.message 是“无效的 XSD 架构”。
标签: node.js xml validation schema