Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there ANY cross-platform way of validating xml against an xsd in javascript?

As far as I can tell, the only way of doing it is to use the Microsoft DOM object, but as far as I'm aware this isn't universally available, if you're browsing with Firefox on Linux for example.

For reasons of security and minimizing network traffic I can't pass the xml to an external tool to validate (much as I wish I could). Is there any way of getting javascript to do this regardless of the browser/platform being used?

like image 257
Flynn1179 Avatar asked Jun 26 '10 12:06

Flynn1179


3 Answers

Might be a tad late for you but maybe it'll help future searchers: http://syssgx.github.io/xml.js/

like image 141
mrt Avatar answered Sep 19 '22 13:09

mrt


For browsers that provide it, you can use ActiveX and MSXML. This blog provides a tutorial on using it to do validation.

For Mozilla there is SchemaValidation developed as part of the XForms extension.

Beyond that, there was an SO user asking about his own validator. His question and information may be a place to start if you end up going that route.

See also the javascript and xsd tags on SO when used together.

However I'd suggest that you may want to look into an alternative - validating server-side, perhaps, or checking business logic by using XSLT to transform your XML and thereby prove that it meets your needs.

like image 23
justkt Avatar answered Sep 19 '22 13:09

justkt


Ok, after a fair amount of research, it seems the simple answer to this one is 'no', unless I write my own validator in javascript.

like image 21
Flynn1179 Avatar answered Sep 20 '22 13:09

Flynn1179