文件格式:
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<Levels>
<level>
<LevelName>level_1</LevelName>
<LevelNumber>1</LevelNumber>
<Unlock>0</Unlock>
<starNumber>0</starNumber>
<HighestScore>0</HighestScore>
</level>
<level>
<LevelName>level_2</LevelName>
<LevelNumber>2</LevelNumber>
<Unlock>1</Unlock>
<starNumber>0</starNumber>
<HighestScore>0</HighestScore>
</level>
<level>
<LevelName>level_3</LevelName>
<LevelNumber>3</LevelNumber>
<Unlock>1</Unlock>
<starNumber>0</starNumber>
<HighestScore>0</HighestScore>
</level>
<level>
<LevelName>level_4</LevelName>
<LevelNumber>4</LevelNumber>
<Unlock>1</Unlock>
<starNumber>0</starNumber>
<HighestScore>0</HighestScore>
</level>
<level>
<LevelName>level_5</LevelName>
<LevelNumber>5</LevelNumber>
<Unlock>1</Unlock>
<starNumber>0</starNumber>
<HighestScore>0</HighestScore>
</level>
<level>
<LevelName>level_6</LevelName>
<LevelNumber>6</LevelNumber>
<Unlock>1</Unlock>
<starNumber>0</starNumber>
<HighestScore>0</HighestScore>
</level>
<level>
<LevelName>level_7</LevelName>
<LevelNumber>7</LevelNumber>
<Unlock>1</Unlock>
<starNumber>0</starNumber>
<HighestScore>0</HighestScore>
</level>
<level>
<LevelName>level_8</LevelName>
<LevelNumber>8</LevelNumber>
<Unlock>1</Unlock>
<starNumber>0</starNumber>
<HighestScore>0</HighestScore>
</level>
<level>
<LevelName>level_9</LevelName>
<LevelNumber>9</LevelNumber>
<Unlock>1</Unlock>
<starNumber>0</starNumber>
<HighestScore>0</HighestScore>
</level>
<level>
<LevelName>level_10</LevelName>
<LevelNumber>10</LevelNumber>
<Unlock>1</Unlock>
<starNumber>0</starNumber>
<HighestScore>0</HighestScore>
</level>
<level>
<LevelName>level_11</LevelName>
<LevelNumber>11</LevelNumber>
<Unlock>1</Unlock>
<starNumber>0</starNumber>
<HighestScore>0</HighestScore>
</level>
<level>
<LevelName>level_12</LevelName>
<LevelNumber>12</LevelNumber>
<Unlock>1</Unlock>
<starNumber>0</starNumber>
<HighestScore>0</HighestScore>
</level>
<level>
<LevelName>level_13</LevelName>
<LevelNumber>13</LevelNumber>
<Unlock>1</Unlock>
<starNumber>0</starNumber>
<HighestScore>0</HighestScore>
</level>
<level>
<LevelName>level_14</LevelName>
<LevelNumber>14</LevelNumber>
<Unlock>1</Unlock>
<starNumber>0</starNumber>
<HighestScore>0</HighestScore>
</level>
<level>
<LevelName>level_15</LevelName>
<LevelNumber>15</LevelNumber>
<Unlock>1</Unlock>
<starNumber>0</starNumber>
<HighestScore>0</HighestScore>
</level>
</Levels>
</rss>
-----------------------------分隔线function GameStep:Parser()
-- bodylocal defaulter=CCUserDefault:sharedUserDefault()
function string.split(s, delimiter)
if s==nil or s=='' or delimiter==nil then
return nil
end
local result = {}
for match in (s..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match)
end
return result
end
--local file='res.xmlData.Chapter1.xml'
CCFileUtils:sharedFileUtils():addSearchPath("res/xmlData/")
-- self:enterScene("MainScene")
local path = CCFileUtils:sharedFileUtils():fullPathForFilename("Chapter1.xml")
print("有路径??????????????????")
if io.exists(path) then
print("有路径啊")
print(path)
end
local fs=io.open(path,'rb')
local fs_data=fs:read('*all')
local chapter_data_tb=string.split(fs_data,'</level>')
for k,v in pairs(chapter_data_tb) do
for level_name,level_num,unlock,start_num,highest_score in string.gmatch(v, '<LevelName>(.+)</LevelName>\n%s+<LevelNumber>(%d+)</LevelNumber>\n%s+<Unlock>(%d+)</Unlock>\n%s+<starNumber>(%d+)</starNumber>\n%s+<HighestScore>(%d+)</HighestScore>') do
print('\n level_name:',level_name,'level_num:',level_num,'unlock:',unlock,'start_num:',start_num,'highest_score:',highest_score)
end
end
fs:close()
end