LogicalMessage.prototype.toXMLDoc = function () { this.validate(); var doc = new libxml.Document(), xsdName = this.XSDName; var root = doc.node(this.rootNodeName); var ns = root.defineNamespace(this.namespace); root.namespace(ns); this.appendToElement(root); return readFileAsync(this.XSDFilepath) .then(function (buffer) { return parseXMLAsync(buffer, {}); }) .then(function (xsdDoc) { //HACK find a way to create al elements inside a file //with the f-ing root namespace //reparsing does that, but at which price? var prova = libxml.parseXmlString(doc.toString()); console.log(prova.toString()); if (!prova.validate(xsdDoc)) { var err = new XSDError('Xsd validation failed invalid document'); err.validationErrors = prova.validationErrors; throw err; } return prova; }); };
.then(function (xsdDoc) { //HACK find a way to create al elements inside a file //with the f-ing root namespace //reparsing does that, but at which price? var prova = libxml.parseXmlString(doc.toString()); console.log(prova.toString()); if (!prova.validate(xsdDoc)) { var err = new XSDError('Xsd validation failed invalid document'); err.validationErrors = prova.validationErrors; throw err; } return prova; });
fs.readFile(xmlPath, function (error, data) { if (error) { console.error(error); process.exit(1); } try { var doc = libxml.Document.fromXml(data, { dtdvalid: true, nonet: true, baseUrl: null, }); } catch(error) { console.error(error); process.exit(1); } console.log('okay'); });