Flynn1179
Flynn1179

Reputation: 12075

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?

Upvotes: 16

Views: 6229

Answers (3)

mrt
mrt

Reputation: 1749

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

Upvotes: 10

justkt
justkt

Reputation: 14776

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.

Upvotes: 9

Flynn1179
Flynn1179

Reputation: 12075

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.

Upvotes: 5

Related Questions