node.js - Invalid XSD schema using libxmljs with nodejs -
I posted a problem on the libxmljs repository and it has been closed because they think that someone at this level The problem is not Lib's, so I post it here.
I am trying to validate an XLIFF file with the XML schema provided by the OASIS, but I get an error with XSD.
Error: Request._callback (/Users/fluxb0x/Tests/xliff_parser/main.js at Document.validate (/ Users / fluxb0x / test / xliff_parser / node_modules / libxmljs / lib / document. Js: 73: 17) Invalid invalid XSD schema: 25:21 at Request.emit) (events.self.callback (/Users/fluxb0x/Tests/xliff_parser/node_modules/request/request.js:19922) (events. Js: 98: 17) On request. At IncomingMessage (20: 117 events.js) at Request.emit (/Users/fluxb0x/Tests/xliff_parser/node_modules/request/request.js/11604). At IncomingMessage.emit (/Users/fluxb0x/Tests/xliff_parser/node_modules/request/request.js:111:12) (events.js: 117: 20) at _stream_readable.js: 938: 16 process._tickCallback (on node. JS: 41 9: 13)
I used the Oxygen XML Editor to test authentication and it becomes without problems.
This is the XLIFF file exported by me:
This is an XSD file provided by OSIS:
Very large file
Thanks for the help.
As you've noticed,
libxmljs a XML schema file Gives the error while validating with which the second imports
& lt; Xsd: import namespace = "http://www.w3.org/XML/1998/namespace" schema location = ".xml.xsd" />
This is because the process of relative path of schema location is calculated on the current working directory. The Workaround directory is changing before valid:
fs.readFile (schemaPath, {encoding: 'UTF8'}, function (Hey, XSD) {if ( I) CB (fault); CWD = process.cwd (); process.chdir (path.dirname (schemaPath)); xsdDoc = libxml.parseXml (XSD); xmlDoc = libxml.parseXml (content); var production = XmlDoc.validate (xsdDoc); process.chdir (cwd); CB (undefined, xmlDoc.validationErrors);});
I'm not sure how
libxml handles this: Although the referenced file synchronous is loaded and I think it is sub-symmetric is.
This solution is only for local files, I do not know how to solve a remote schema location, such as your example (
schemaLocation = "http: //www.w3. Org / 2001 / xml.xsd "/ / Gt; )
Even if this is not a real solution then I think it can be helpful.
Comments
Post a Comment