I got a xml file that consists of data that has a range, eg: 100-150.
How can I make the " - " appears in my apps? or in another words, how can I make it display the whole range exactly like the one is in the XML?
Thanks.
I got a xml file that consists of data that has a range, eg: 100-150.
How can I make the " - " appears in my apps? or in another words, how can I make it display the whole range exactly like the one is in the XML?
Thanks.
Can you post the actual XML and where did you get your XML parser?
Here is the part of the xml
\</description\> \<link\>http://domain.com\</link\> \<pubDate\>30 Jul 2014 1pm\</pubDate\> \<data\>Data : 51-55 \</data\>
While the xml parser,
print("found item") if founditem == true then for i=1,#Item do for j=1,#Item[i].child do if Item[i].child[j].name == "pubDate" then CurrentTime[i] = Item[i].child[j].value CurrentTime[i] = changePubdateToNum(CurrentTime[i]) foundpubdate = true end if Item[i].child[j].name == "data" then DataReading[i] = Item[i].child[j].value DataReading[i] = simplifyData(DataReading[i]) foundData = true end end end end
With reference from : http://coronalabs.com/blog/2013/03/19/updating-mobile-game-content-in-runtime-guest-post/
I don’t know what simplifyData is doing for you and I don’t know why you are putting Item[i].child[j].value into PSIReading[i] then immediately overwriting PSIReading[i] with simplfyData( Datareading[i] ). Shouldn’t this be:
PSIReading[i] = simplifyData( Item[i].child[j].value] )
???
Any way, the value in the tag is “Data : 51-55”. I’m still not 100% sure what you’re trying to do here. If you just want to display: 51-55 then you need to parse out the “Data:”. Are you wanting to get the 51 into one variable and the 55 into another? Or do you want to add spaces around the hyphen?
Rob
What I am trying to achieve is to just display “51 - 55”.
Under simplifyData is have something like this:
function simplifyData(data) data = string.gsub(data,"%a", "") data = string.gsub(data,"%(","") data = string.gsub(data,"%)","") data = string.gsub(data,"%s","") data = string.gsub(data,":","") data = string.gsub(data,"-","") data = tonumber(data) return data end
I am able to display the number but the number became “5155” without the hyphen.
*If i remove this
data = string.gsub(psi,"-","")
I would get an error saying “attempt to compare nil with number”
Look at string.match(). A pattern like:
local min, max = string.match(yourstring, “Data:%d-%d”)
or something like that.
Still having the same error “attempt to compare nil with number”.
Any ideas?
Can you post some code along with the exact error message including the whole back trace from your console log?
Can you post the actual XML and where did you get your XML parser?
Here is the part of the xml
\</description\> \<link\>http://domain.com\</link\> \<pubDate\>30 Jul 2014 1pm\</pubDate\> \<data\>Data : 51-55 \</data\>
While the xml parser,
print("found item") if founditem == true then for i=1,#Item do for j=1,#Item[i].child do if Item[i].child[j].name == "pubDate" then CurrentTime[i] = Item[i].child[j].value CurrentTime[i] = changePubdateToNum(CurrentTime[i]) foundpubdate = true end if Item[i].child[j].name == "data" then DataReading[i] = Item[i].child[j].value DataReading[i] = simplifyData(DataReading[i]) foundData = true end end end end
With reference from : http://coronalabs.com/blog/2013/03/19/updating-mobile-game-content-in-runtime-guest-post/
I don’t know what simplifyData is doing for you and I don’t know why you are putting Item[i].child[j].value into PSIReading[i] then immediately overwriting PSIReading[i] with simplfyData( Datareading[i] ). Shouldn’t this be:
PSIReading[i] = simplifyData( Item[i].child[j].value] )
???
Any way, the value in the tag is “Data : 51-55”. I’m still not 100% sure what you’re trying to do here. If you just want to display: 51-55 then you need to parse out the “Data:”. Are you wanting to get the 51 into one variable and the 55 into another? Or do you want to add spaces around the hyphen?
Rob
What I am trying to achieve is to just display “51 - 55”.
Under simplifyData is have something like this:
function simplifyData(data) data = string.gsub(data,"%a", "") data = string.gsub(data,"%(","") data = string.gsub(data,"%)","") data = string.gsub(data,"%s","") data = string.gsub(data,":","") data = string.gsub(data,"-","") data = tonumber(data) return data end
I am able to display the number but the number became “5155” without the hyphen.
*If i remove this
data = string.gsub(psi,"-","")
I would get an error saying “attempt to compare nil with number”
Look at string.match(). A pattern like:
local min, max = string.match(yourstring, “Data:%d-%d”)
or something like that.
Still having the same error “attempt to compare nil with number”.
Any ideas?
Can you post some code along with the exact error message including the whole back trace from your console log?