XML parser’s white space processing

Published 2014-10-27 | (Compatible with SDK 3.5,4.5,5.0,5.1 and 2012,2013,2014 models)

Differences in text nodes processing on the 2012 platform.

Processing of white space (tab, newline, space) with respect to Node Recognition is different at the time of XML parsing.

As a solution, white space node processing function is added at the time of XML Data parsing. Browser wise processing method for White Space is different. In case of Webkit, it skips the empty fields.

The below is a Sample XML for Parsing.

        <value>ADAMS J</value>
        <value>  </value> <!--Two spaces-->
        <value>Programmers 'R' Us</value>
        <value>     </value> <!--A Tab-->

Source Files


The files needed for the sample application are here.

Bad example

var message = MessageBody[0].firstChild ? MessageBody[0].firstChild.nodeValue : 'default Value';

Good example

var tmpFirstChild = getFirstChild(MessageBody[0]) ;
var message = tmpFirstChild ? tmpFirstChild.nodeValue : 'default value';

function getFirstChild (tmpnode) {
    var tmpChild=tmpnode.firstChild;
        while (tmpChild) {
            if( (tmpChild.nodeType == 8) || ((tmpChild.nodeType == 3) && !(/[^\t\n\r\ ]/.test(tmpChild.data)))) {
                tmpChild = tmpChild.nextSibling;
            } else {
                return tmpChild;
    return null;