有什么跨平台的方法可以根据javascript中的xsd验证xml吗?

时间:2021-08-06 17:17:41

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.

就我所知,唯一的方法是使用Microsoft DOM对象,但是就我所知,这并不是普遍可用的,例如,如果您在Linux上使用Firefox浏览的话。

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?

出于安全性和最小化网络通信量的原因,我无法将xml传递给外部工具进行验证(这是我所希望的)。无论使用什么浏览器/平台,是否有任何方法可以让javascript实现这一点?

3 个解决方案

#1


9  

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

对于提供它的浏览器,可以使用ActiveX和MSXML。这个博客提供了使用它进行验证的教程。

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

对于Mozilla来说,在XForms扩展中开发了SchemaValidation。

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.

除此之外,还有一个SO用户询问他自己的验证器。如果你走那条路线,他的问题和信息可能是一个开始的地方。

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

在一起使用时,还可以看到javascript和xsd标记。

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.

然而,我建议您可以考虑另一种选择——验证服务器端,或者通过使用XSLT转换XML来检查业务逻辑,从而证明它满足您的需求。

#2


9  

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

对您来说,这可能有点晚,但它可能会帮助未来的搜索者:http://syssgx.github.io/xml.js/

#3


4  

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.

经过大量的研究,这个问题的简单答案似乎是“不”,除非我用javascript编写自己的验证器。

#1


9  

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

对于提供它的浏览器,可以使用ActiveX和MSXML。这个博客提供了使用它进行验证的教程。

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

对于Mozilla来说,在XForms扩展中开发了SchemaValidation。

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.

除此之外,还有一个SO用户询问他自己的验证器。如果你走那条路线,他的问题和信息可能是一个开始的地方。

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

在一起使用时,还可以看到javascript和xsd标记。

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.

然而,我建议您可以考虑另一种选择——验证服务器端,或者通过使用XSLT转换XML来检查业务逻辑,从而证明它满足您的需求。

#2


9  

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

对您来说,这可能有点晚,但它可能会帮助未来的搜索者:http://syssgx.github.io/xml.js/

#3


4  

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.

经过大量的研究,这个问题的简单答案似乎是“不”,除非我用javascript编写自己的验证器。