一个工作的 nodeJS 模块,用于在本地验证 sitemap.xml
A working nodeJS module to validate locally a sitemap.xml
我一直在四处寻找,none 可用的 npm 模块似乎验证了 本地现有 sitemap.xml!我的意思是像 this online tool.
这样的验证
如何在 nodeJS 中本地验证 sitemap.xml
?
您使用 XSD 验证您的 sitemap.xml
文件。在您的情况下,您想使用以下 sitemap.xsd.
然后使用模块根据 XSD 验证 XML 文件,例如 libxml-xsd
.
var xsd = require('libxml-xsd');
xsd.parseFile(schemaPath, function(err, schema){
schema.validate(documentString, function(err, validationErrors){
// err contains any technical error
// validationError is an array, null if the validation is ok
});
});
在此代码段中(来自 libxml-xsd
doc)schemaPath
是您的 XSD 文件的路径,documentString
是包含您的 sitemap.xml
内容的字符串.
我一直在四处寻找,none 可用的 npm 模块似乎验证了 本地现有 sitemap.xml!我的意思是像 this online tool.
这样的验证如何在 nodeJS 中本地验证 sitemap.xml
?
您使用 XSD 验证您的 sitemap.xml
文件。在您的情况下,您想使用以下 sitemap.xsd.
然后使用模块根据 XSD 验证 XML 文件,例如 libxml-xsd
.
var xsd = require('libxml-xsd');
xsd.parseFile(schemaPath, function(err, schema){
schema.validate(documentString, function(err, validationErrors){
// err contains any technical error
// validationError is an array, null if the validation is ok
});
});
在此代码段中(来自 libxml-xsd
doc)schemaPath
是您的 XSD 文件的路径,documentString
是包含您的 sitemap.xml
内容的字符串.