PtokaX forum

Archive => Archived 5.0 boards => Help with scripts => Topic started by: Jemte on 03 May, 2005, 01:38:50

Title: parsing RegisteredUsers.xml
Post by: Jemte on 03 May, 2005, 01:38:50
I am trying to read through the registered user list so I can get an access list available for viewing.

_, _, tag = string.find(sLine, "(<.*>).*")
i thought the function only replied back with the result that was within the ()s but when i print out the value of 'tag' it shows the entire line 'Jemte' ive tried using '%S+' instead of '.*' but then the tag is 'nil'.

any suggestions/help would be appreciated.
Title:
Post by: Jemte on 03 May, 2005, 02:17:45
ok i found out that the <(.*)> reads from the beginning of the line til the end

Jemte returns 'Nick>Jemte
i tried "<(%S+)>(%w+)<(%S+)>" for the pattern but its not working...ill keep trying tho
Title:
Post by: bastya_elvtars on 03 May, 2005, 02:56:28
%b<>(.+)%b<>
means: anything surrounded by 2 thingies that are < and >

More precise would be to assign the variable name as well.

Like:
local _,_,varname,value=string.find(line,"<(.+)>(.+)%b<>")
-- and then:
table[varname]=value
Title:
Post by: Herodes on 03 May, 2005, 12:21:05
its far more better to use frmHub:GetRegisteredUsers() ..

but if you are trying to parse an xml you need to scan the string( contents of xml file ) progressively rather than pMatched..

str = [[

Smth
SmthElse

SmMore
SmMore

]]

you need to get the first tag..
s,e, sTag, sRest = string.find( str, "<([^>]+)>(.*)" )then you need to get the contents of that tag..
s,e, sContents, sTmp = string.find( sRest, "(.-)(.-)" )This is the main principle to parse the xml.. Carrying on from here you'll need to create a function with a while-loop to parse the sContents and the sTmp, putting the [sTag]= sContents inside a table.

That all has been done for you .. Look in the how to section There is a function I played with for a while ..

Btw:
as far as pattern matching is concerned '-' means not greedy in the results.. while '*' means greedy..
Example:
str = "12"
string.find ( str, "<(.*)>" )
-- this will result in "one>12string.find( str, "<(.-)>" )
-- this will result in "one"
I hope its clear ;)