Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19436] Android: Ti.XML.parseString() did not recognise tag name without namespace

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionInvalid
Resolution Date2015-09-08T03:08:57.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterShuo Liang
AssigneeAshraf Abu
Created2015-08-31T02:53:47.000+0000
Updated2015-09-08T03:08:57.000+0000

Description

Reproduce Step:

1. Simply run the following code in a default project.
var response= '<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">';
response += '<env:Header/><env:Body>';
response += '<ns0:findEmirateLookupsView1Response xmlns:ns0="/uaq/db/si/model/common/types/">';
response += '<ns0:result xmlns:ns1="/uaq/db/si/model/common/" xmlns:ns0="/uaq/db/si/model/common/types/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns1:EmirateLookupsViewSDO">'; 
response += '<ns1:EmirateId>1</ns1:EmirateId>';
response += '<ns1:EmiratenameEn>Dubai</ns1:EmiratenameEn>';
response += '<ns1:EmiratenameAr>دبي</ns1:EmiratenameAr>';
response += '</ns0:result>';
response += '<ns0:result xmlns:ns1="/uaq/db/si/model/common/" xmlns:ns0="/uaq/db/si/model/common/types/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns1:EmirateLookupsViewSDO">'; 
response += '<ns1:EmirateId>2</ns1:EmirateId>'; 
response += '<ns1:EmiratenameEn>Abu Dhabi</ns1:EmiratenameEn>'; 
response += '<ns1:EmiratenameAr>أبوظبي</ns1:EmiratenameAr>'; 
response += '</ns0:result>'; 
response += '<ns0:result xmlns:ns1="/uaq/db/si/model/common/" xmlns:ns0="/uaq/db/si/model/common/types/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns1:EmirateLookupsViewSDO">'; 
response += '<ns1:EmirateId>3</ns1:EmirateId>'; 
response += '<ns1:EmiratenameEn>Sharjah</ns1:EmiratenameEn>'; 
response += '<ns1:EmiratenameAr>الشارقة</ns1:EmiratenameAr>'; 
response += '</ns0:result>'; 
response += '<ns0:result xmlns:ns1="/uaq/db/si/model/common/" xmlns:ns0="/uaq/db/si/model/common/types/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns1:EmirateLookupsViewSDO">'; 
response += '<ns1:EmirateId>4</ns1:EmirateId>'; 
response += '<ns1:EmiratenameEn>Al Ain</ns1:EmiratenameEn>';
response += '<ns1:EmiratenameAr>العين</ns1:EmiratenameAr>';
response += '</ns0:result>';
response += '<ns0:result xmlns:ns1="/uaq/db/si/model/common/" xmlns:ns0="/uaq/db/si/model/common/types/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns1:EmirateLookupsViewSDO">';
response += '<ns1:EmirateId>5</ns1:EmirateId>';
response += '<ns1:EmiratenameEn>Ras al-Khaimah</ns1:EmiratenameEn>';
response += '<ns1:EmiratenameAr>راس الخيمه</ns1:EmiratenameAr>';
response += '</ns0:result>';
response += '</ns0:findEmirateLookupsView1Response>'; 
response += '</env:Body></env:Envelope>';

var result = Ti.XML.parseString(response); 
Ti.API.info(result);

var rootNode = result.getElementsByTagName("EmiratenameEn"); 
Ti.API.info('emirates list length==>> ' + rootNode.length); 

Expect Result:

The XML tag should be recongise.

Actual Result:

On android, the tag can't be recongised. But on iOS, it works well.

Note:

If using full tag name with namespace (ns1:EmiratenameEn), it will work well. But this XML is a response from httpClient, the namespace is changing every time.

Comments

  1. Ashraf Abu 2015-09-04

    There's this method, http://docs.appcelerator.com/platform/latest/#!/api/Titanium.XML.Document-method-getElementsByTagNameNS that does search with namespaces. You can use:
       var rootNode = result.getElementsByTagNameNS("*","EmiratenameEn"); 
       
    In android to get this to work. Full code would be:
       var response= '<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">';
       response += '<env:Header/><env:Body>';
       response += '<ns0:findEmirateLookupsView1Response xmlns:ns0="/uaq/db/si/model/common/types/">';
       response += '<ns0:result xmlns:ns1="/uaq/db/si/model/common/" xmlns:ns0="/uaq/db/si/model/common/types/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns1:EmirateLookupsViewSDO">'; 
       response += '<ns1:EmirateId>1</ns1:EmirateId>';
       response += '<ns1:EmiratenameEn>Dubai</ns1:EmiratenameEn>';
       response += '<ns1:EmiratenameAr>دبي</ns1:EmiratenameAr>';
       response += '</ns0:result>';
       response += '<ns0:result xmlns:ns1="/uaq/db/si/model/common/" xmlns:ns0="/uaq/db/si/model/common/types/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns1:EmirateLookupsViewSDO">'; 
       response += '<ns1:EmirateId>2</ns1:EmirateId>'; 
       response += '<ns1:EmiratenameEn>Abu Dhabi</ns1:EmiratenameEn>'; 
       response += '<ns1:EmiratenameAr>أبوظبي</ns1:EmiratenameAr>'; 
       response += '</ns0:result>'; 
       response += '<ns0:result xmlns:ns1="/uaq/db/si/model/common/" xmlns:ns0="/uaq/db/si/model/common/types/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns1:EmirateLookupsViewSDO">'; 
       response += '<ns1:EmirateId>3</ns1:EmirateId>'; 
       response += '<ns1:EmiratenameEn>Sharjah</ns1:EmiratenameEn>'; 
       response += '<ns1:EmiratenameAr>الشارقة</ns1:EmiratenameAr>'; 
       response += '</ns0:result>'; 
       response += '<ns0:result xmlns:ns1="/uaq/db/si/model/common/" xmlns:ns0="/uaq/db/si/model/common/types/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns1:EmirateLookupsViewSDO">'; 
       response += '<ns1:EmirateId>4</ns1:EmirateId>'; 
       response += '<ns1:EmiratenameEn>Al Ain</ns1:EmiratenameEn>';
       response += '<ns1:EmiratenameAr>العين</ns1:EmiratenameAr>';
       response += '</ns0:result>';
       response += '<ns0:result xmlns:ns1="/uaq/db/si/model/common/" xmlns:ns0="/uaq/db/si/model/common/types/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns1:EmirateLookupsViewSDO">';
       response += '<ns1:EmirateId>5</ns1:EmirateId>';
       response += '<ns1:EmiratenameEn>Ras al-Khaimah</ns1:EmiratenameEn>';
       response += '<ns1:EmiratenameAr>راس الخيمه</ns1:EmiratenameAr>';
       response += '</ns0:result>';
       response += '</ns0:findEmirateLookupsView1Response>'; 
       response += '</env:Body></env:Envelope>';
        
       var result = Ti.XML.parseString(response); 
       Ti.API.info(result);
        
       var rootNode = result.getElementsByTagNameNS("*","EmiratenameEn"); 
       Ti.API.info('emirates list length==>> ' + rootNode.length); 
       
    [~sliang] If this solves the issue, I'll resolve this ticket.
  2. Shuo Liang 2015-09-04

    It works for me, and now waiting for customer's reply. Thanks a lot. [~msamah]
  3. Ashraf Abu 2015-09-08

    Closing this as invalid.

JSON Source