text: /*
   *  Copyright 2014 SeaClouds
   *  Contact: SeaClouds
   *
   *      Licensed under the Apache License, Version 2.0 (the "License");
   *      you may not use this file except in compliance with the License.
   *      You may obtain a copy of the License at
   *
   *          http://www.apache.org/licenses/LICENSE-2.0
   *
   *      Unless required by applicable law or agreed to in writing, software
   *      distributed under the License is distributed on an "AS IS" BASIS,
   *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *      See the License for the specific language governing permissions and
   *      limitations under the License.
   */
  
  //TODO: Refactor to JS objects
  function isValidYAML(yaml) {
      try {
          jsyaml.safeLoad(yaml);
      } catch (e) {
          return false;
      }
      return true;
  }
  
  function isValidJSON(json) {
      try {
          JSON.parse(json);
      } catch (e) {
          return false;
      }
      return true;
  }
  
  // TODO: Enable IE support
  function isValidXML(xml) {
      var parser = new DOMParser();
      // attempt to parse the passed-in xml
      var dom = parser.parseFromString(xml, 'text/xml');
      return xml.length && !isParseError(dom);
  }
  
  function isParseError(parsedDocument) {
      // parser and parsererrorNS could be cached on startup for efficiency
      var parser = new DOMParser(),
          errorneousParse = parser.parseFromString('<', 'text/xml'),
          parsererrorNS = errorneousParse.getElementsByTagName("parsererror")[0].namespaceURI;
  
      if (parsererrorNS === 'http://www.w3.org/1999/xhtml') {
          // In PhantomJS the parseerror element doesn't seem to have a special namespace, so we are just guessing here :(
          return parsedDocument.getElementsByTagName("parsererror").length > 0;
      }
  
      return parsedDocument.getElementsByTagNameNS(parsererrorNS, 'parsererror').length > 0;
  };