admin管理员组文章数量:1356566
I have a string that may or may not contain valid xml content. How can I test to see if that particular string is a valid xml document or not? I would prefer this to be in jQuery or just plain javascript.
thanks.
I have a string that may or may not contain valid xml content. How can I test to see if that particular string is a valid xml document or not? I would prefer this to be in jQuery or just plain javascript.
thanks.
Share Improve this question asked Mar 12, 2014 at 23:59 NinerNiner 2,2057 gold badges39 silver badges50 bronze badges 1- possible duplicate of Regex to check for XML if it is well formed – attila Commented Mar 13, 2014 at 0:09
1 Answer
Reset to default 9You can try this JQuery code:
function isXML(xml){
try {
xmlDoc = $.parseXML(xml); //is valid XML
return true;
} catch (err) {
// was not XML
return false;
}
}
本文标签: javascriptTest to see if a string is an XML document or not in jQueryStack Overflow
版权声明:本文标题:javascript - Test to see if a string is an XML document or not in jQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743972288a2570738.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论