title: jQuery parseXML: detecting errors
body: <p>For a utility that asks a user to enter xml (say, from a file on a local disk), one can use jQuery's parseXML  to convert the string into an XML document.  This will work fine with well formed XML, but will fail silently if the XML is malformed.</p>
  
  <p>For example:</p>
  
  <pre><code>xmltest=' &lt;dog&gt;&lt;arf&gt;33 &lt;/arf&gt;&lt;/dog&gt;'; 
  xmlDoc = $.parseXML( xmltest) ;
  xml = $(xmlDoc );
  achild=xml.children(0).children(0);
  alert('Content of child 1= '+achild.html(); 
  </code></pre>
  
  <p>will correctly yield: <b>Content of child 1= 33</b></p>
  
  <p><p>  However</p>
  
  <pre><code>xmltest=' &lt;dog&gt;&lt;arf&gt;33 &lt;/arf1&gt;&lt;/dog&gt;';
  xmlDoc = $.parseXML( xmltest) ;
  xml = $(xmlDoc );
  ...
  </code></pre>
  
  <p>will fail silently. </p>
  
  <p>More precisely; messages are displayed in the console. For example, Firefox displays:</p>
  
  <pre><code>[21:08:47.731] mismatched tag. Expected: &lt;/arf&gt; 
  [21:08:47.731] Error: Invalid XML:&lt;dog&gt;&lt;arf&gt;33 &lt;/arf1&gt;&lt;/dog&gt;
  </code></pre>
  
  <p><p>
  Ie and chrome report similar messages.
   <p></p>
  
  <p><i>The question:</i> is there any way that javascript, or jquery, can detect this failure and access these error messages? The goal being to tell the user what kind of problems his XML file may have.
   <p>
  Note that one reason I am playing with this is to workaround the inability of Chrome to read local xml files using $.get (yes yes yes I understand it is a security thing, but it is also a pain in the neck if you want to use XML files to store a lot of attribute information, and don't want to run chrome from a command line. And what about IE?). 
   <p>
  Using try and catch helps a bit...:
   <p> </p>
  
  <pre><code>xmltest=' &lt;dog&gt;&lt;arf&gt;33 &lt;/arf1&gt;&lt;/dog&gt;';
  try {
      xmlDoc = $.parseXML( xmltest) ;
  } 
  catch(e) {
      wow='';
      for (m in e) wow=wow+' : '+m+'='+e[m];
      alert(e+':error== '+wow); return 1;
  }
  </code></pre>
  
  <p>Yields in Firefox:</p>
  
  <pre><code>Error: Invalid XML:   &lt;dog&gt;&lt;arf&gt;33 &lt;/arf1&gt;&lt;/dog&gt; :error==  : fileName=file:///D:/docs/carCosts/jquery-1.10.2.js : lineNumber=516 : columnNumber=2
  </code></pre>