3

I want to parse this XML http://steamcommunity.com/id/GreenMarineValve?xml=1 with Lua 5.1, there are some libraries like LuaXML but they do not support parsing from the URL.

Would you give me a link to a library to do that if there is any or some advice to achieve my goal?

-

More details for those who have experience with Steam's Web API, I basically want to convert "customURL" to Steam Community ID (steamID64), but I see there is no other way doing it without parsing that XML file, I could parse it from the URL if it was JSON format instead of XML.

Is there an API I'm missing which will take the customURL as a parameter and return the communityID ? Some related links to WebAPI: https://developer.valvesoftware.com/wiki/Steam_Web_API https://partner.steamgames.com/documentation/webapi

Fiat Pax
  • 417
  • 6
  • 18

1 Answers1

2

If you know how to get the contents of a URL into a Lua string, then getting the fields you want is simple:

function get(data,name)
    return data:match("<"..name..">(.-)</"..name..">")
end

-- assumes C contains the downloaded contents
print(get(C,"customURL"))
print(get(C,"steamID64"))
lhf
  • 70,581
  • 9
  • 108
  • 149
  • This is indeed very useful code snippet for me, but I don't know how to get the contents of a URL. – Fiat Pax Aug 14 '13 at 03:04
  • 2
    @Fiat, try [LuaSocket](http://luaforge.net/projects/luasocket/) or [LuaCURL](http://luacurl.luaforge.net). See http://stackoverflow.com/questions/11413127/downloading-and-storing-files-from-given-url-to-given-path-in-lua. – lhf Aug 14 '13 at 03:06
  • This is going to be way advanced for me, I feel so lost. But this answers my question anyways, I will try to understand it. – Fiat Pax Aug 14 '13 at 03:13
  • 1
    @Fiat, if you have `curl` or `wget` installed, you can open a pipe to them and read from it: `f=io.popen("curl -s http://steamcommunity.com/id/GreenMarineValve?xml=1"); C=f:read"*a"; f:close()`. – lhf Aug 14 '13 at 03:20
  • Thank you so much really, I will install curl and try this. – Fiat Pax Aug 14 '13 at 03:25