Resource Directory Web references

I have a main.lua in which I download some XML from a webservice, add an XSLT reference element to the front of the file and save it to the system.TemporaryDirectory.

At program start, it copies an XSLT file from the system.ResourceDirectory to the system.TemporaryDirectory.

Once all that is done, and I can see it is by dumping it all into a textbox, I open up a web popup and give it the URL of the XML file in the system.TemporaryDirectory.

All I get is a grey box and I don’t know why. My code is below, minus the proprietary web service URLs, I’m afraid…

Matt.

[lua]display.setStatusBar( display.HiddenStatusBar ) – guess what this does

– displays all XML downloaded in one textbox in the top 3rd of the screen
local textbox = native.newTextBox( 0, 0, display.contentWidth, display.contentHeight/3 )

– takes a fresh copy of the XSLT files from the app’s directory and puts them in the tmp dir
function copy( source, dest )
local rpath = system.pathForFile( source, system.ResourceDirectory )
local rfile = io.open( rpath, “r” )

local str = “”
if (rfile) then
str = rfile:read("*l")
io.close( rfile )
end

local wpath = system.pathForFile( dest, system.TemporaryDirectory )
local wfile = io.open( wpath, “w” )
wfile:write( str )
io.close( wfile )
end

copy( “feed.xslt”, “feed.xslt” )
copy( “article.xslt”, “article.xslt” )

function save( filename, insert, content )
if (insert) then
textbox.text = textbox.text … insert
end
local path = system.pathForFile( filename, system.TemporaryDirectory )
local file = io.open( path, “w” )
if (insert) then
file:write( insert )
end
file:write( content )
io.close( file )
end

– dumps first XML block into text box in top 3rd of screen
function renderlogon( event )
print(“RENDER LOGON…”)
print(event.response)
save( “logon.xml”, nil, event.response )
textbox.text = event.response
print(“END”)

network.request( FEEDURL, “GET”, renderfeed )
end

– dumps second XML block into web popup in the middle 3rd of the screen
function renderfeed( event )
local xslt = ‘<?xml-stylesheet type="text/xsl" href="feed.xslt"?>’
print(“RENDER FEED…”)
print(event.response)
save( “feed.xml”, xslt, event.response )
textbox.text = textbox.text … event.response
native.showWebPopup( 0, display.contentHeight/3, display.contentWidth, display.contentHeight/3, “feed.xml”, {base=system.TemporaryDirectory} )
print(“END”)

network.request( ARTICLEURL, “GET”, renderarticle )
end

– dumps the last XML block into web popup in the bottom 3rd of the screen
function renderarticle( event )
local xslt = ‘<?xml-stylesheet type="text/xsl" href="article.xslt"?>’
print(“RENDER ARTICLE…”)
print(event.response)
save( “article.xml”, xslt, event.response )
textbox.text = textbox.text … event.response
native.showWebPopup( 0, (display.contentHeight/3)*2, display.contentWidth, display.contentHeight/3, “article.xml”, {base=system.TemporaryDirectory} )
print(“END”)
end

network.request( LOGONURL, “GET”, renderlogon )[/lua]
[import]uid: 8271 topic_id: 6348 reply_id: 306348[/import]

Ok, so the web popup argument base should be baseUrl, but it’s not working either way.

Any help from the community here would be awesome!

Thanks,

Matt. [import]uid: 8271 topic_id: 6348 reply_id: 21946[/import]

Damnit.

Line 13 should also be changed to:

[lua]str = rfile:read("*a")[/lua]

But it is still not working. Would anyone have a working example of downloading an XML file, adding an XSL tag to it and loading it locally with an XSLT file into a web popup?

I really shouldn’t do this when so tired…

Matt. [import]uid: 8271 topic_id: 6348 reply_id: 22147[/import]

Check the console logs and see if it’s giving you a “file not found” with the path you supplied from pathForFile(). It appears to be broken in the current version.

If this is the case (Ansca haven’t confirmed or denied the issue) then a lot of file functionality - such as the io library and sprite sheet loads - simply won’t work.

newImage() is OK if you supply the baseDirectory parameter.

If the path is OK for you I’d like to know so I can try to figure out what’s wrong with my setup. [import]uid: 3953 topic_id: 6348 reply_id: 22483[/import]

I’m not seeing any problems, that I can detect, with that. I’ll double check.

My issue with device debugging is that the recommended (or only) method I’ve seen to dump to the console from the device doesn’t work for me. [import]uid: 8271 topic_id: 6348 reply_id: 22662[/import]

Hi,

I am new in Lua, and I wanna call my web services so how to use this in Lua in above i hv read about that u hv get the xml from web services
I wanna use like :

http://test.test.test/test.asmx

and in this asmx use method and get the responce of return xml file.

is there any way to use this??
Thankx
Krunal. [import]uid: 33757 topic_id: 6348 reply_id: 23596[/import]

That’s been answered on other threads, but just look in the docs on the site for the synchronous or asynchronous network calls. [import]uid: 8271 topic_id: 6348 reply_id: 23599[/import]

@ MarkHenryC I’ve checked that and it always seems fine. Maybe the problem is that my only device which will dump to the xcode console is the ipad. But I got the code working on device either way, and it seems that my final problem was that only one web popup can be used at a time. :frowning: [import]uid: 8271 topic_id: 6348 reply_id: 23600[/import]

HI,

Thankx for reply,

I hv checked that…article and doc, but not getting any success.

I’d make that same application but in my simulator.not getting any responce.

Here I am giving you my code:
local function networkListener( event )

print(“test”)

if ( event.isError ) then
print( “Network error!”)
else
print ( "RESPONSE: " … event.response )
end
end

headers = {}
headers[“Content-Type”] = “application/json”
headers[“Accept-Language”] = “en-US”

body = “This is an example request body.”

local params = {}
params.headers = headers
params.body = body

network.request( “http://mytest.applicatoin.test/getWebservices.asmx”, “GET”, networkListener, params)
even that listener not call. and i m not getting that print statement.

Plz help me…:frowning:
Thanks
Krunal. [import]uid: 33757 topic_id: 6348 reply_id: 23844[/import]

Hi,

Anybody help to me…of my previous post…i am waiting for reply.
Thankx,
Krunal. [import]uid: 33757 topic_id: 6348 reply_id: 24169[/import]

hi horacebury,

kindly please provide me that threads link if you have…,b’cas my problem is still unsolved.
Thankx,
Krunal. [import]uid: 33757 topic_id: 6348 reply_id: 24170[/import]

I had that problem - the event listener not even firing on simulator. It is a known issue that the simulator has trouble with proxies, so try building the code for device and dumping the event.response into a native.showAlert. [import]uid: 8271 topic_id: 6348 reply_id: 24171[/import]