Titanium JIRA Archive
Appcelerator Community (AC)

[AC-2879] I am trying to call webservices file in our Application, but i am getting error, there is no proper documentation availbale that how to access remote xml webservices in Titanium

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionInvalid
Resolution Date2012-02-23T10:11:57.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsbranch-v8, tbs-1.9.0
ReporterBharat Bhushan
AssigneeMauro Parra-Miranda
Created2012-02-08T01:53:32.000+0000
Updated2016-03-08T07:47:50.000+0000

Description

var xhr = Titanium.Network.createHTTPClient(); xhr.onload = function() { Ti.API.info('twitter xml ' + this.responseXML + ' text ' + this.responseText); var doc = this.responseXML.documentElement; var elements = doc.getElementsByTagName("screen_name"); var screenName = elements.item(0); Ti.API.info("screenname = " + screenName.text); var screenname = Ti.UI.createLabel({ textAlign:'center', height:'auto', width:'auto', top:20, text:screenName.text }); Ti.UI.currentWindow.add(screenname); var textarea = Ti.UI.createTextArea({borderRadius:5,borderWidth:2,borderColor:'#999',backgroundColor:'#111',color:'yellow',bottom:10,left:10,right:10,height:300,font:{fontFamily:'courier',fontSize:10}}); textarea.value = this.responseText; Ti.UI.currentWindow.add(textarea); }; xhr.open('GET', 'http://202.53.15.170/aguva/php_xml/php_xml.php?GetOpr=GetTopBizList'); xhr.send();

Comments

  1. Tim Poulsen 2012-02-08

    Did you see the document at https://wiki.appcelerator.org/display/guides/Working+with+XML+Data
  2. Ingo Muschenetz 2012-02-08

    Moved from TISTUD tracker.
  3. Bharat Bhushan 2012-02-08

    I am getting this error when i use this code in app.js : var xhr = Ti.Network.createHTTPClient(); xhr.open("GET","http://v2.0.news.tmg.s3.amazonaws.com/feeds/news.xml"); xhr.onload = function() { try { var doc = this.responseXML.documentElement; var items = doc.getElementsByTagName("item"); var x = 0; var doctitle = doc.evaluate("//channel/title/text()").item(0).nodeValue; for (var c=0;c 0) { var media = thumbnails.item(0).getAttribute("url"); var title = item.getElementsByTagName("title").item(0).text; var row = Ti.UI.createTableViewRow({height:80}); var label = Ti.UI.createLabel({ text:title, left:72, top:5, bottom:5, right:5 }); row.add(label); var img; if (Titanium.Platform.name == 'android') { // iphone moved to a single image property - android needs to do the same img = Ti.UI.createImageView({ image:media, left:5, height:60, width:60 }); } else { img = Ti.UI.createImageView({ image:media, left:5, height:60, width:60 }); } row.add(img); data[x++] = row; row.url = item.getElementsByTagName("link").item(0).text; } } var tableview = Titanium.UI.createTableView({data:data}); Titanium.UI.currentWindow.add(tableview); tableview.addEventListener('click',function(e) { var w = Ti.UI.createWindow({title:doctitle}); var wb = Ti.UI.createWebView({url:e.row.url}); w.add(wb); var b = Titanium.UI.createButton({ title:'Close', style:Titanium.UI.iPhone.SystemButtonStyle.PLAIN }); w.setLeftNavButton(b); b.addEventListener('click',function() { w.close(); }); w.open({modal:true}); }); } catch(E) { alert(E); } }; xhr.send(); and In console Window i am getting the output like this : D/AndroidRuntime( 415): D/AndroidRuntime( 415): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<< D/AndroidRuntime( 415): CheckJNI is ON D/AndroidRuntime( 415): --- registering native functions --- D/dalvikvm( 360): GC_EXPLICIT freed 561 objects / 32032 bytes in 220ms D/PackageParser( 60): Scanning package: /data/app/vmdl70533.tmp D/dalvikvm( 60): GC_FOR_MALLOC freed 7379 objects / 418976 bytes in 106ms I/PackageManager( 60): Removing non-system package:com.appcelerator.com I/ActivityManager( 60): Force stopping package com.appcelerator.com uid=10041 I/Process ( 60): Sending signal. PID: 392 SIG: 9 I/ActivityManager( 60): Force finishing activity HistoryRecord{43f19220 com.appcelerator.com/.AguvaActivity} I/UsageStats( 60): Unexpected resume of com.android.launcher while already resumed in com.appcelerator.com D/dalvikvm( 60): GC_FOR_MALLOC freed 7268 objects / 376504 bytes in 127ms I/WindowManager( 60): WIN DEATH: Window{4400c1b0 com.appcelerator.com/ti.modules.titanium.ui.TiTabActivity paused=false} I/WindowManager( 60): WIN DEATH: Window{440b6a20 com.appcelerator.com/com.appcelerator.com.AguvaActivity paused=true} W/InputManagerService( 60): Got RemoteException sending setActive(false) notification to pid 392 uid 10041 D/PackageManager( 60): Scanning package com.appcelerator.com I/PackageManager( 60): Package com.appcelerator.com codePath changed from /data/app/com.appcelerator.com-1.apk to /data/app/com.appcelerator.com-2.apk; Retaining data and using new I/PackageManager( 60): /data/app/com.appcelerator.com-2.apk changed; unpacking D/installd( 35): DexInv: --- BEGIN '/data/app/com.appcelerator.com-2.apk' --- D/dalvikvm( 422): DexOpt: 'Lorg/apache/commons/codec/binary/Base64;' has an earlier definition; blocking out D/dalvikvm( 422): DexOpt: 'Lorg/apache/commons/codec/binary/Hex;' has an earlier definition; blocking out D/dalvikvm( 422): DexOpt: 'Lorg/w3c/dom/UserDataHandler;' has an earlier definition; blocking out D/dalvikvm( 422): DexOpt: not verifying 'Lorg/apache/commons/codec/binary/Base64;': multiple definitions D/dalvikvm( 422): DexOpt: not verifying 'Lorg/apache/commons/codec/binary/Hex;': multiple definitions I/dalvikvm( 422): DexOpt: not resolving ambiguous class 'Lorg/apache/commons/codec/binary/Hex;' I/dalvikvm( 422): DexOpt: not resolving ambiguous class 'Lorg/apache/commons/codec/binary/Base64;' I/dalvikvm( 422): DexOpt: not resolving ambiguous class 'Lorg/apache/commons/codec/binary/Base64;' D/dalvikvm( 422): DexOpt: not verifying 'Lorg/w3c/dom/UserDataHandler;': multiple definitions I/dalvikvm( 422): DexOpt: not resolving ambiguous class 'Lorg/apache/commons/codec/binary/Hex;' I/dalvikvm( 422): DexOpt: not resolving ambiguous class 'Lorg/apache/commons/codec/binary/Base64;' D/dalvikvm( 422): DexOpt: load 359ms, verify 1701ms, opt 95ms D/installd( 35): DexInv: --- END '/data/app/com.appcelerator.com-2.apk' (success) --- W/PackageManager( 60): Code path for pkg : com.appcelerator.com changing from /data/app/com.appcelerator.com-1.apk to /data/app/com.appcelerator.com-2.apk W/PackageManager( 60): Resource path for pkg : com.appcelerator.com changing from /data/app/com.appcelerator.com-1.apk to /data/app/com.appcelerator.com-2.apk D/PackageManager( 60): Services: org.appcelerator.titanium.analytics.TiAnalyticsService D/PackageManager( 60): Activities: com.appcelerator.com.AguvaActivity org.appcelerator.titanium.TiActivity org.appcelerator.titanium.TiTranslucentActivity org.appcelerator.titanium.TiModalActivity ti.modules.titanium.ui.TiTabActivity ti.modules.titanium.ui.android.TiPreferencesActivity I/ActivityManager( 60): Force stopping package com.appcelerator.com uid=10041 I/installd( 35): move /data/dalvik-cache/data@app@com.appcelerator.com-2.apk@classes.dex -> /data/dalvik-cache/data@app@com.appcelerator.com-2.apk@classes.dex D/PackageManager( 60): New package installed in /data/app/com.appcelerator.com-2.apk I/ActivityManager( 60): Force stopping package com.appcelerator.com uid=10041 D/dalvikvm( 113): GC_EXPLICIT freed 72 objects / 3160 bytes in 50ms D/dalvikvm( 60): GC_EXPLICIT freed 7930 objects / 478256 bytes in 190ms W/RecognitionManagerService( 60): no available voice recognition services found I/installd( 35): unlink /data/dalvik-cache/data@app@com.appcelerator.com-1.apk@classes.dex D/AndroidRuntime( 415): Shutting down VM D/jdwp ( 415): adbd disconnected I/dalvikvm( 415): JNI: AttachCurrentThread (from ???.???) I/AndroidRuntime( 415): NOTE: attach of thread 'Binder Thread #3' failed D/AndroidRuntime( 428): D/AndroidRuntime( 428): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<< D/AndroidRuntime( 428): CheckJNI is ON D/AndroidRuntime( 428): --- registering native functions --- I/ActivityManager( 60): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.appcelerator.com/.AguvaActivity } D/AndroidRuntime( 428): Shutting down VM D/jdwp ( 428): adbd disconnected I/ActivityManager( 60): Start proc com.appcelerator.com for activity com.appcelerator.com/.AguvaActivity: pid=435 uid=10041 gids={1015, 3003} I/dalvikvm( 428): JNI: AttachCurrentThread (from ???.???) I/AndroidRuntime( 428): NOTE: attach of thread 'Binder Thread #3' failed I/TiApplication( 435): (main) [0,0] checkpoint, app created. I/TiApplication( 435): (main) [271,271] Titanium 1.8.0.1 (2011/12/22 13:09 fbdc96f) D/dalvikvm( 435): GC_FOR_MALLOC freed 3378 objects / 311616 bytes in 71ms D/TiFastDev( 435): (main) [388,659] Enabling Fastdev on port 55154 D/TiFastDev( 435): (main) [125,784] sent tokens successfully D/TiFastDev( 435): (main) [2,786] Fastdev session handshake succesful. I/TiApplication( 435): (main) [8,794] Titanium Javascript runtime: v8 D/dalvikvm( 435): Trying to load lib /data/data/com.appcelerator.com/lib/libstlport_shared.so 0x43e37450 D/dalvikvm( 435): Added shared lib /data/data/com.appcelerator.com/lib/libstlport_shared.so 0x43e37450 D/dalvikvm( 435): No JNI_OnLoad found in /data/data/com.appcelerator.com/lib/libstlport_shared.so 0x43e37450, skipping init D/dalvikvm( 435): Trying to load lib /data/data/com.appcelerator.com/lib/libkroll-v8.so 0x43e37450 W/TiApplication( 435): (main) [190,984] activity stack is emtpy, unable to get current activity I/TiRootActivity( 435): (main) [0,0] checkpoint, on root activity create, savedInstanceState: null W/TiApplication( 435): (main) [769,769] activity stack is emtpy, unable to get current activity W/TiApplication( 435): (main) [0,769] activity stack is emtpy, unable to get current activity W/TiApplication( 435): (main) [0,769] activity stack is emtpy, unable to get current activity D/dalvikvm( 435): Added shared lib /data/data/com.appcelerator.com/lib/libkroll-v8.so 0x43e37450 E/TiApplication( 435): (KrollRuntimeThread) [2198,2967] APP PROXY: ti.modules.titanium.app.AppModule@43ea4af0 D/TiAssetHelper( 435): Fetching "app.js" with Fastdev... E/dalvikvm( 435): Could not find class 'org.apache.http.entity.mime.content.StringBody', referenced from method ti.modules.titanium.network.TiHTTPClient.addPostData W/dalvikvm( 435): VFY: unable to resolve new-instance 695 (Lorg/apache/http/entity/mime/content/StringBody;) in Lti/modules/titanium/network/TiHTTPClient; D/dalvikvm( 435): VFY: replacing opcode 0x22 at 0x000a D/dalvikvm( 435): VFY: dead code 0x000c-0014 in Lti/modules/titanium/network/TiHTTPClient;.addPostData (Ljava/lang/String;Ljava/lang/String;)V E/dalvikvm( 435): Could not find class 'org.apache.http.entity.mime.content.FileBody', referenced from method ti.modules.titanium.network.TiHTTPClient.addTitaniumFileAsPostData W/dalvikvm( 435): VFY: unable to resolve new-instance 694 (Lorg/apache/http/entity/mime/content/FileBody;) in Lti/modules/titanium/network/TiHTTPClient; D/dalvikvm( 435): VFY: replacing opcode 0x22 at 0x0008 E/dalvikvm( 435): Could not find class 'org.apache.http.entity.mime.content.FileBody', referenced from method ti.modules.titanium.network.TiHTTPClient.addTitaniumFileAsPostData W/dalvikvm( 435): VFY: unable to resolve new-instance 694 (Lorg/apache/http/entity/mime/content/FileBody;) in Lti/modules/titanium/network/TiHTTPClient; D/dalvikvm( 435): VFY: replacing opcode 0x22 at 0x0062 D/dalvikvm( 435): VFY: dead code 0x000a-0026 in Lti/modules/titanium/network/TiHTTPClient;.addTitaniumFileAsPostData (Ljava/lang/String;Ljava/lang/Object;)I D/dalvikvm( 435): VFY: dead code 0x0064-0070 in Lti/modules/titanium/network/TiHTTPClient;.addTitaniumFileAsPostData (Ljava/lang/String;Ljava/lang/Object;)I D/TiHttpClient( 435): (KrollRuntimeThread) [675,3642] Setting ready state to 1 E/dalvikvm( 435): Could not find class 'org.apache.http.entity.mime.MultipartEntity', referenced from method ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run W/dalvikvm( 435): VFY: unable to resolve new-instance 692 (Lorg/apache/http/entity/mime/MultipartEntity;) in Lti/modules/titanium/network/TiHTTPClient$ClientRunnable; D/dalvikvm( 435): VFY: replacing opcode 0x22 at 0x00d0 D/dalvikvm( 435): VFY: dead code 0x00d2-0152 in Lti/modules/titanium/network/TiHTTPClient$ClientRunnable;.run ()V D/dalvikvm( 435): VFY: dead code 0x01e1-025a in Lti/modules/titanium/network/TiHTTPClient$ClientRunnable;.run ()V D/dalvikvm( 435): VFY: dead code 0x0301-0314 in Lti/modules/titanium/network/TiHTTPClient$ClientRunnable;.run ()V I/ActivityManager( 60): Starting activity: Intent { cmp=com.appcelerator.com/ti.modules.titanium.ui.TiTabActivity (has extras) } D/dalvikvm( 435): GC_FOR_MALLOC freed 5373 objects / 428152 bytes in 80ms I/TiRootActivity( 435): (main) [0,0] checkpoint, on root activity resume. activity = com.appcelerator.com.AguvaActivity@43e9e6c0 D/dalvikvm( 435): GC_FOR_MALLOC freed 693 objects / 38288 bytes in 63ms I/dalvikvm-heap( 435): Grow heap (frag case) to 3.024MB for 87396-byte allocation D/dalvikvm( 435): GC_FOR_MALLOC freed 8 objects / 368 bytes in 54ms W/TiTabActivity( 435): (main) [439,439] Notifying TiTabGroup, activity is created D/TiHttpClient( 435): (TiHttpClient-1) [104,543] Setting ready state to 2 D/TiHttpClient( 435): (TiHttpClient-1) [0,543] Setting ready state to 3 D/dalvikvm( 435): GC_EXTERNAL_ALLOC freed 842 objects / 45736 bytes in 63ms W/TiUIImageView( 435): (main) [313,856] The url property of ImageView is deprecated, use image instead. W/TiDrawableReference( 435): (main) [78,934] Bitmap final bounds could not be determined. If bitmap is loaded, it won't be scaled. W/TiUIImageView( 435): (main) [69,1003] The url property of ImageView is deprecated, use image instead. D/TiHttpClient( 435): (TiHttpClient-1) [54,1057] Setting ready state to 4 W/TiDrawableReference( 435): (main) [10,1067] Bitmap final bounds could not be determined. If bitmap is loaded, it won't be scaled. D/dalvikvm( 435): GC_FOR_MALLOC freed 1100 objects / 286256 bytes in 79ms I/dalvikvm-heap( 435): Grow heap (frag case) to 3.683MB for 162362-byte allocation D/dalvikvm( 435): GC_FOR_MALLOC freed 209 objects / 11112 bytes in 82ms W/TiUIImageView( 435): (main) [217,1284] The url property of ImageView is deprecated, use image instead. D/dalvikvm( 435): GC_FOR_MALLOC freed 370 objects / 85744 bytes in 62ms I/dalvikvm-heap( 435): Grow heap (frag case) to 3.863MB for 162330-byte allocation D/dalvikvm( 435): GC_FOR_MALLOC freed 59 objects / 3184 bytes in 73ms W/TiUIImageView( 435): (main) [263,1547] The url property of ImageView is deprecated, use image instead. D/dalvikvm( 435): GC_FOR_MALLOC freed 811 objects / 504824 bytes in 72ms D/dalvikvm( 435): GC_EXTERNAL_ALLOC freed 900 objects / 168808 bytes in 71ms D/dalvikvm( 435): GC_FOR_MALLOC freed 6297 objects / 544464 bytes in 61ms I/ALERT ( 435): (KrollRuntimeThread) [1630,3177] {} I/ActivityManager( 60): Displayed activity com.appcelerator.com/ti.modules.titanium.ui.TiTabActivity: 3400 ms (total 9714 ms) W/ActivityManager( 60): Launch timeout has expired, giving up wake lock! W/ActivityManager( 60): Activity idle timeout for HistoryRecord{43fa0728 com.appcelerator.com/.AguvaActivity} D/dalvikvm( 360): GC_EXPLICIT freed 600 objects / 38528 bytes in 69ms D/dalvikvm( 369): GC_EXPLICIT freed 833 objects / 57600 bytes in 75ms W/InputManagerService( 60): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@43e856f0 D/dalvikvm( 376): GC_EXPLICIT freed 2072 objects / 145928 bytes in 92ms D/dalvikvm( 113): GC_EXPLICIT freed 727 objects / 41384 bytes in 70ms W/TiAnalyticsSvc( 435): (Thread-14) [22810,25987] Analytics Service Started I/TiAnalyticsSvc( 435): (Thread-14) [98,26085] Sending 1 analytics events. D/dalvikvm( 435): GC_FOR_MALLOC freed 9260 objects / 506064 bytes in 95ms W/TiAnalyticsSvc( 435): (Thread-14) [1674,27759] Stopping Analytics Service D/SntpClient( 60): request time failed: java.net.SocketException: Address family not supported by protocol D/SntpClient( 60): request time failed: java.net.SocketException: Address family not supported by protocol D/dalvikvm( 169): GC_FOR_MALLOC freed 3292 objects / 448144 bytes in 75ms I/EventLogService( 169): Aggregate from 1328762829186 (log), 1328762829186 (data)
  4. Tim Poulsen 2012-02-09

    With a quick glance, I'm going to guess that this line is what's causing the error: doc.evaluate("//channel/title/text()").item(0).nodeValue; Instead, you should use something like:
       var channel = xml.documentElement.getElementsByTagName("channel");
       var title = channel.item(0).getElementsByTagName("title").item(0).text;
       
    Check out the code at the following location. I updated it to pull from the RSS feed you're trying to use. It loads up the stories just fine. You can see in it how I "walk" the XML tree (see the network.js file). This example project uses the same techniques described in the wiki. https://github.com/skypanther/TitaniumIntro/tree/master/RSSReader You're welcome to use the code in that repo in your project, it's Apache FOSS licensed.
  5. Mauro Parra-Miranda 2012-02-23

    Following Tim's example, this is working fine.
  6. Mauro Parra-Miranda 2013-11-24

    Invalid issue.

JSON Source