使用jQuery.parseXML(data)进行XML验证 [英] XML validation using jQuery.parseXML( data )

查看:79
本文介绍了使用jQuery.parseXML(data)进行XML验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一下我是否可以使用 jQuery.parseXML(data)进行验证XML字符串?

I wanted to ask if I could use the jQuery.parseXML(data) to validate XML string?

我的意思是我知道它用于解析XML,如果XML无效,我会收到一条错误消息,但是每次在XML中甚至出现小错误时,函数都会失败吗?

I mean I know it's used for parsing XML, and if the XML is not valid I will get an error message, but will the function fail every time that there will be even a minor error in the XML?

我已经尝试过使用Google搜索,但是发现的只是解析而不是验证.

I've tried googling about it, but all I found is regarding parsing, and not about validation.

谢谢!

推荐答案

不,不是通过jQuery(至少不是在Mozilla中,而且很可能是在其他非IE浏览器中).

No, not via jQuery (at least not in Mozilla and most likely the other non-IE browsers).

对于IE,请在 http://msdn.microsoft.com/en-us/library/windows/desktop/ms754585%28v=vs.85%29.aspx ,带有loadXML,您不能使用它验证XML文档是否符合架构.",因此显然是jQuery中 http://上使用的代码code.jquery.com/jquery-latest.js 也不会验证.

In the case of IE, it is stated at http://msdn.microsoft.com/en-us/library/windows/desktop/ms754585%28v=vs.85%29.aspx , with loadXML, "You cannot use it to validate the XML document against a schema.", so apparently the code used in jQuery at http://code.jquery.com/jquery-latest.js will not validate either.

但是,某些代码位于 http://www.stylusstudio.com/xsllist/200301/post50460.html 似乎建议在IE(仅)中使用正确的IE(至少在Msxml2.DOMDocument的4.0版本中)是可行的,因为根据

However, some code at http://www.stylusstudio.com/xsllist/200301/post50460.html seems to suggest it is possible in IE (only) with the right IE--at least with the 4.0 version of Msxml2.DOMDocument -- since according to http://msdn.microsoft.com/en-us/library/aa468547.aspx#beginner_failure , "the MSXML parser will validate your document against a DTD or schema if either has been specified in the document" (unless validateOnParse property is set to false).

但是,在Mozilla和其他浏览器中,它们无法执行验证(我认为在Ajax的DOMParser()情况下,它们已经加载了外部DTD,但现在看来对我而言不起作用,无论如何) ,甚至实体也不会加载到常规网站中.

However, with Mozilla and the other browsers, these do not perform validation (I thought they had loaded external DTDs in the case of DOMParser() of Ajax, but this does not seem to work for me now, and in any case, even entities are not loaded in regular websites).

我不记得是否 http://code.google.com/p/jssaxparser/ http://debeissat.nicolas.free.fr/relaxng.php 将支持外部验证,但是我认为您需要朝着这种方向发展.

I don't recall whether http://code.google.com/p/jssaxparser/ or http://debeissat.nicolas.free.fr/relaxng.php will support external validation, but I think you'd need to go in this kind of direction.

您需要使用XML吗?也许JSONSchema可以满足您的需求? http://json-schema.org/implementations.html .

Do you need to use XML? Perhaps JSONSchema could meet your needs? http://json-schema.org/implementations.html .

这篇关于使用jQuery.parseXML(data)进行XML验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆