title: Parsing XML with Typescript and xml2js
body: <p>I am trying to work with Express and parse an XML body.  I am using the bodyparser for text, but cannot get the xml2js to parse my  XML into a usable format.</p>
  
  <pre><code>import * as xml2js from 'xml2js';
  try {
      const XML:string = '&lt;Pan&gt;0000000000000702203&lt;/Pan&gt;';
  
      xml2js.parseString(XML, {trim: true}, function (err, result) {
          if(err) console.log(err);
          console.log(result); 
      });
  } catch (e) {
      console.log(e);
  }
  </code></pre>
  
  <p>either does not work:</p>
  
  <pre><code>try {
      xml2js.parseString(XML, {trim: true}, (err, result) =&gt; {
          if(err) console.log(err);
          console.log(result); 
      });
  } catch (e) {
      console.log(e);
  }
  </code></pre>
  
  <p>When running this in the VSCode debugger and the code immediate skips over the function and does not process the xml2js.parseString(). err and result never get values.</p>
  
  <p>I have also tried with it using the Parser() class:</p>
  
  <pre><code>const p:xml2js.Parser = new xml2js.Parser();
  p.parseString(XML, (err:{}, result:{}) =&gt; {
      if(err) console.log(err);
      console.log(result); 
  });
  
  p.parseString(XML, function(err:{}, result:{}) {
      if(err) console.log(err);
      console.log(result); 
  });
  </code></pre>
  
  <p>This does the same thing and does not work or populate the err,result.</p>
  
  <p>Update: 2018/10/11: I have tried debuging this, and it appears the sax.parser is working and returning data.  I have done the following:</p>
  
  <pre><code>console.log(xml2js.parseString(XML, (err, result) =&gt; {
      if (err) {
          console.log(err);
      }
  });
  </code></pre>
  
  <p>and I do get the SaxParser returned as an object in VSCode which I can interrogate and see my results in, but I do not get my callback function called.</p>
  
  <p>Debug:</p>
  
  <pre><code>SAXParser {comment: "", sgmlDecl: "", textNode: "", tagName: "", doctype: "", …}
  </code></pre>
  
  <p>The xml2js.parseString though is supposed to not return anything, as the definition has this as a void.</p>