10

I need to know, if there is a solution which works in all major browsers for validating an xml against an xsd. I don't have the time for creating the actual validation functionality myself. It's for a project which needs to be done in 2 weeks as an exam for my apprenticeship.

Doing an xml validator as a jQuery login would be nice. So i got 2 Questions.

Is there a pre-made xml validation plugin/functionality in JS or jQuery like PHP's http://php.net/manual/de/domdocument.schemavalidate.php ? No ActiveX, since ActiveX is just supported by IE (afaik). And it is unhandy, if i remember correctly, the user always has to agree with it.

I always just found, selfmade validation of XML (no schemas) or stuff made with ActiveX. So, if there is no xml validation plugin/functionality to which i just can pass a xml and a xsd, i would like to get a quick introduction on how i would do it myself, so i can imagen it better. Probably it's quick a lot of work for making my own xml validation against xsd, right?

Thanks

handy
  • 696
  • 3
  • 9
  • 22
  • **From where** does the XSD and XML come to your script? – ilyes kooli Jun 07 '12 at 16:57
  • I'm not the author of the original question, but in my case (which was the reason to add the bounty) both would be hosted on the same server that's also providing the HTML and JavaScript sources. – Chris Jun 07 '12 at 20:44
  • @Chris, would it be OK if the solution works only in Internet Explorer? – Halil Özgür Jun 14 '12 at 11:41
  • 1
    @HalilÖzgür no, I'm sorry not. It should be cross platform (and then IE support would be optional in my case). I know that IE has the possibility to use MSXML... – Chris Jun 14 '12 at 20:09

3 Answers3

8

I would suggest to perform an Ajax request, validate on the server, and return the response to JS.

ilyes kooli
  • 11,959
  • 14
  • 50
  • 79
  • 2
    This would be a nice and valid workaround to keep going. But sadly not a solution to the question about validating it on the client. – Chris Jun 07 '12 at 20:50
  • Go with Ajax and validate it server-side. There is no pure-js solution at this point - only the one using ActiveX. – c2h5oh Jun 07 '12 at 21:35
8

I know that you prefer a jQuery solution, but there is something that it was developed in JS, and performs just the way you want.

http://syssgx.github.io/xml.js/

This link gives 3 ways of interaction:

  • (via browser) drag-and-drop XML files and then validate;
  • (via browser) copy&paste XML content into "textareas" and then validate;
  • (import/inlcude) adding the JS file to your webapp and then validate (as shown on page).
Paulo Oliveira
  • 2,411
  • 1
  • 31
  • 47
3

The best answer I found so far was Is there ANY cross-platform way of validating xml against an xsd in javascript?
But that's not very satisfying and nearly two years old - ages for the fast developmet that's going on on the browser side

Community
  • 1
  • 1
Chris
  • 3,265
  • 5
  • 37
  • 50