【问题标题】:Using Node.js I validated the xml schema for xml schemas and it failed. I don't know why使用 Node.js,我验证了 xml 模式的 xml 模式,但它失败了。我不知道为什么
【发布时间】: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');
    }
});

输出是:

模式模式格式良好
架构架构无效的架构

这对我来说没有意义。

【问题讨论】:

标签: node.js xml validation schema


【解决方案1】:

您为什么忽略异常e 中的信息?如果你不看错误信息,你不知道它为什么失败也就不足为奇了。

话虽如此,https://www.w3.org/2009/XMLSchema/XMLSchema.xsd 的架构文档似乎是 XSD 1.1 的架构(尽管可能不是最终的架构,因为 XSD 1.1 建议于 2012 年发布)并且 libXML 处理器仅支持 XSD 1.0。

(我不知道用于 Node.js 的 XSD 1.1 处理器。也许有一天我们会在 Saxon-JS 产品中包含模式处理,但目前还没有。)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 2019-06-20
    • 2010-11-03
    相关资源
    最近更新 更多