Wei Posted July 5, 2012 Share Posted July 5, 2012 Hi. I'm making a radio system with ability to add your own radio stations. It will be xml based. So i've made scipt to createfile. But how can I get the table of station 1 and 2 at the same time. function createFileHandler() local xmlFile = xmlCreateFile("stations.xml","stations") local stationInfo = xmlCreateChild(xmlFile, "station") xmlNodeSetAttribute(stationInfo, "name", "Welcome to our serve") xmlNodeSetAttribute(stationInfo, "url", "Is the color") local stationInfo1 = xmlCreateChild(xmlFile, "station") xmlNodeSetAttribute(stationInfo1, "name", "Welcome to our serve") xmlNodeSetAttribute(stationInfo1, "url", "Is the color") xmlSaveFile(xmlFile) end addCommandHandler("createfile", createFileHandler) function createFileHandle1r() local meta = xmlLoadFile ( "stations.xml" ) local info = xmlFindChild ( meta, "station", 0 ) if info then local attrs = xmlNodeGetAttributes ( info ) for name,value in pairs ( attrs ) do outputChatBox( value ) end end xmlUnloadFile ( meta ) end addCommandHandler("ce", createFileHandle1r) And xml. "Welcome to our serve" url="Is the color"> "Welcome to our serve" url="Is the color"> Link to comment
Guest Guest4401 Posted July 6, 2012 Share Posted July 6, 2012 local meta = xmlLoadFile("stations.xml") stationsTable = xmlNodeGetChildren(meta) Link to comment
naz19 Posted July 6, 2012 Share Posted July 6, 2012 local stations = xmlNodeGetChildren ( meta ) --get all node children local station1, station2 = unpack ( stations ) -- then unpack table local attrs = xmlNodeGetAttributes ( station1 ) local attrs2 = xmlNodeGetAttributes ( station2 ) for name,value in pairs ( attrs ) do outputChatBox( value ) end for name,value in pairs ( attrs2 ) do outputChatBox( value ) end -- u can also do local stations = xmlGetNodeChildren ( meta ) for i, station in ipairs ( stations ) do local url = xmlNodeGetAttribute ( station, "url") local name = xmlNodeGetAttribute ( station, "name") outputChatBox ( tostring ( i ) .. ' : url = ' .. tostring ( url ) .. ' name = ' .. tostring ( name ) ) end Link to comment
Guest Guest4401 Posted July 6, 2012 Share Posted July 6, 2012 I failed to understand what exactly you are trying to achieve. If you are willing to show the attributes of every node: local meta = xmlLoadFile("stations.xml") stationsTable = xmlNodeGetChildren(meta) for index,node in ipairs(stationsTable) do for key, attribute in pairs(xmlNodeGetAttributes(node)) do outputChatBox(key.." = "..attribute) end end Link to comment
Guest Guest4401 Posted July 6, 2012 Share Posted July 6, 2012 Yeah. Works. Thanks You're welcome. Link to comment
Wei Posted July 6, 2012 Author Share Posted July 6, 2012 function createFileHandler() if not xmlLoadFile("stations.xml") then local xmlFile = xmlCreateFile("stations.xml","stations") local stationInfo = xmlCreateChild(xmlFile, "station") xmlNodeSetAttribute(stationInfo, "name", "Power 181") xmlNodeSetAttribute(stationInfo, "url", "http://www.181.fm/asx.php?station=181-uktop40&style=&a..scription=") local stationInfo1 = xmlCreateChild(xmlFile, "station") xmlNodeSetAttribute(stationInfo1, "name", "NonStopPlay.com") xmlNodeSetAttribute(stationInfo1, "url", "http://www.nonstopplay.com/broadband.asx") xmlSaveFile(xmlFile) end end trigger with createFileHandler() why doesn't work ? Link to comment
naz19 Posted July 6, 2012 Share Posted July 6, 2012 Maybe handle it by command, event, key or use it in handled function? Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now