最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Test to see if a string is an XML document or not in jQuery - Stack Overflow

programmeradmin3浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 9

You can try this JQuery code:

function isXML(xml){
    try {
        xmlDoc = $.parseXML(xml); //is valid XML
        return true;
    } catch (err) {
        // was not XML
        return false;
    }
}
发布评论

评论列表(0)

  1. 暂无评论