我一直在环顾四周,没有一个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
is是你的XSD文件的路径,documentString
是一个包含你的sitemap.xml
内容的字符串。