src/parser_utils.js
function parseNodeValue(node) {
  const childNodes = node && node.childNodes && [...node.childNodes];
  if (!childNodes) {
    return {};
  }

  // Trying to find and parse CDATA as JSON
  const cdatas = childNodes.filter((childNode) => childNode.nodeName === '#cdata-section');
  if (cdatas && cdatas.length > 0) {
    try {
      return JSON.parse(cdatas[0].data);
    } catch (e) {}
  }

  // Didn't find any CDATA or failed to parse it as JSON
  return childNodes.reduce((previousText, childNode) => {
    let nodeText = '';
    switch (childNode.nodeName) {
      case '#text':
        nodeText = childNode.textContent.trim();
        break;
      case '#cdata-section':
        nodeText = childNode.data;
        break;
    }
    return previousText + nodeText;
  }, '');
}
function parseNodeValue(node) {
  const childNodes = node && node.childNodes && [...node.childNodes];
  if (!childNodes) {
    return {};
  }

  // Trying to find and parse CDATA as JSON
  const cdatas = childNodes.filter((childNode) => childNode.nodeName === '#cdata-section');
  if (cdatas && cdatas.length > 0) {
    try {
      return JSON.parse(cdatas[0].data);
    } catch (e) {}
  }

  // Didn't find any CDATA or failed to parse it as JSON
  return childNodes.reduce((previousText, childNode) => {
    let nodeText = '';
    switch (childNode.nodeName) {
      case '#text':
        nodeText = childNode.textContent.trim();
        break;
      case '#cdata-section':
        nodeText = childNode.data;
        break;
    }
    return previousText + nodeText;
  }, '');
}
function parseNodeValue ( node ) { const childNodes = node && node . childNodes && [ ... node . childNodes ] ; if ( ! childNodes ) { return { } ; } // Trying to find and parse CDATA as JSON const cdatas = childNodes . filter ( ( childNode ) => childNode . nodeName === '#cdata-section' ) ; if ( cdatas && cdatas . length > 0 ) { try { return JSON . parse ( cdatas [ 0 ] . data ) ; } catch ( e ) { } } // Didn't find any CDATA or failed to parse it as JSON return childNodes . reduce ( ( previousText , childNode ) => { let nodeText = '' ; switch ( childNode . nodeName ) { case '#text' : nodeText = childNode . textContent . trim ( ) ; break ; case '#cdata-section' : nodeText = childNode . data ; break ; } return previousText + nodeText ; } , '' ) ; }
Parses a node value giving priority to CDATA as a JSON over text, if CDATA is not a valid JSON it is converted to text
@param  {Object} node - The node to parse the value from.
@return {String|Object}
Parses a node value giving priority to CDATA as a JSON over text if CDATA is not a valid JSON it is converted to text