Problem
There appears to be a difference in parsing XML between Android and iOS.
Its required to check the nodeName of the first child found in a particular XML document, "firstChild.nodeName" should return 'LOGON_RESPONSE'. What we get from iOS is 'Text', because the DOM element thinks this is just a text node.
After using a removeWhitespace custom function the discrepancy may be noticeable even easier.
Steps to reproduce
1. Take the XML fragment below
2. Monitor console output
Simple snippet code
var xmlTest = '<?xml version="1.0" encoding="utf-8"?>' +
'<LOGON_RESPONSE ID="0">' +
' <RESULT>ACK</RESULT>' +
' <DATE_TIME>2013-03-28T09:13:42.786125+00:00</DATE_TIME>' +
' <DATA>' +
' <EPOD_SITES>' +
' <EPOD_SITE>' +
' <EPL_SITE_ID>TEST</EPL_SITE_ID>' +
' <EPL_DESCRIPTION>TEST SITE 1</EPL_DESCRIPTION>' +
' </EPOD_SITE>' +
' <EPOD_SITE>' +
' <EPL_SITE_ID>TEST2</EPL_SITE_ID>' +
' <EPL_DESCRIPTION>TEST SITE 2</EPL_DESCRIPTION>' +
' </EPOD_SITE>' +
' </EPOD_SITES>' +
' <EPOD_JOB_GROUPS>' +
' <EPOD_JOB_GROUP>' +
' <EPL_SITE_ID>TEST</EPL_SITE_ID>' +
' <EPL_JOB_GROUP>EXTER</EPL_JOB_GROUP>' +
' <EPL_DESCRIPTION>NEW JOB GROUP</EPL_DESCRIPTION>' +
' </EPOD_JOB_GROUP>' +
' <EPOD_JOB_GROUP>' +
' <EPL_SITE_ID>TEST2</EPL_SITE_ID>' +
' <EPL_JOB_GROUP>EXTER</EPL_JOB_GROUP>' +
' <EPL_DESCRIPTION>NEW JOB GROUP</EPL_DESCRIPTION>' +
' </EPOD_JOB_GROUP>' +
' </EPOD_JOB_GROUPS>' +
' </DATA>' +
'</LOGON_RESPONSE>';
var xml = Ti.XML.parseString(xmlTest);
Ti.API.info('Name of xml nodeName: '+xml.nodeName);
var nodes = xml.documentElement.childNodes;
Ti.API.info(" nodes: " + nodes);
Ti.API.info('Name of first node:'+xml.firstChild.nodeName);
function removeWhitespace(str) {
// Function removes all whitespace from an XML fragment, so it will parse correctly in iOS.
return str.replace(/\>[\t ]+$/g, ">").replace(/\>[\t ]+\</g, "><").replace(/[\t ]+\</g, "<").replace(/\n/g, "");
}
xml = Ti.XML.parseString(removeWhitespace(xmlTest));
Ti.API.info('Name of first node (removeWhitespace):'+xml.firstChild.nodeName);
Ti.API.info('Name of firstChild: '+xml.firstChild);
Ti.API.info('Name of xml nodeName: '+xml.nodeName);
iOS console output
[INFO] : ATest/1.0 (3.1.0.v20130314163255.12bff9f)
[DEBUG] : Loading: /Users/egomez/Library/Application Support/iPhone Simulator/6.1/Applications/6ACEF0D3-63E3-4A8A-906F-ECB1591FCA21/ATest.app/app.js, Resource: app_js
[INFO] : Name of xml nodeName: LOGON_RESPONSE
[INFO] : nodes: [object TiDOMNodeList]
[INFO] : Name of first node:#text
[INFO] : Name of first node (removeWhitespace):RESULT
[INFO] : Name of firstChild: [object TiDOMElement]
[INFO] : Name of xml nodeName: LOGON_RESPONSE
[DEBUG] : Application booted in 17.419994 ms
Android console output
04-08 15:57:04.539: I/TiAPI(3477): Name of xml nodeName: #document
04-08 15:57:04.539: I/TiAPI(3477): nodes: [object NodeList]
04-08 15:57:04.539: I/TiAPI(3477): Name of first node:LOGON_RESPONSE
04-08 15:57:04.554: I/TiAPI(3477): Name of first node (removeWhitespace):LOGON_RESPONSE
04-08 15:57:04.554: I/TiAPI(3477): Name of firstChild: [object Element]
04-08 15:57:04.554: I/TiAPI(3477): Name of xml nodeName: #document
One of my students has discovered this bug independently, or at least one very similar. With the following code, the expected result on both iOS and Android would be be ParentNode. However, it is ChildNode on iOS and ParentNode on Android.
The bug has turned up in their actual app, but he was able to reduce it down and reproduce with the simple test case above. Tested with Ti 3.1.3GA