Skip to content

Instantly share code, notes, and snippets.

@sinetoami
Created March 9, 2021 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sinetoami/8a643df813e5a8995c2d2c868ac73904 to your computer and use it in GitHub Desktop.
Save sinetoami/8a643df813e5a8995c2d2c868ac73904 to your computer and use it in GitHub Desktop.
Validador XSD/XML
import * as fs from "fs";
import * as libxml from "libxmljs";
try {
const xsdStr = fs.readFileSync("RecepcaoNFSe_v1.00.xsd", "utf8");
const xml = fs.readFileSync("teste.xml", "utf8");
const xsd = libxml.parseXml(xsdStr);
const xmlDoc = libxml.parseXml(xml);
console.log(xmlDoc.validate(xsd));
console.log(xmlDoc.validationErrors);
} catch (error) {
console.error(error);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment