Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gideros中带Lua的XmlParser_Lua_Nsxmlparser_Gideros - Fatal编程技术网

Gideros中带Lua的XmlParser

Gideros中带Lua的XmlParser,lua,nsxmlparser,gideros,Lua,Nsxmlparser,Gideros,我正在与Gideros合作,我得到了错误,但我不知道为什么以及如何修复。 错误是: 尝试索引本地“xml\u布局\u x” 我的身材: 这是我的header.xml <rss version="2.0"> <layout> <layout_x>35</layout_x> <layout_y>150</layout_y> <layout_width>825</layo

我正在与Gideros合作,我得到了错误,但我不知道为什么以及如何修复。 错误是:

尝试索引本地“xml\u布局\u x”

我的身材:

这是我的header.xml

<rss version="2.0">         
<layout>
    <layout_x>35</layout_x>
    <layout_y>150</layout_y>
    <layout_width>825</layout_width>

    <image>
        <width>270</width>
        <height>240</height>
    </image>

    <table>
        <layout_x>25</layout_x>

        <tablerow
            textview_name=".Name:"
            edittext_name_height="18"
            edittext_name_width="245"
            edittext_name_offset_x="150"
            textview_born=".Born:"
            textview_weight=".Weight:"
            textview_bio=".Bio:"
            edittext_bio_width="441"
            edittext_bio_height="71"
        />      
    </table>

    <action>
        <name>update</name> 
    </action>   

    <file:path bio="bio_001.txt" image="Avatar_001.png"/>
    <file:path bio="bio_002.txt" image="Avatar_002.png"/>

</layout>
</rss>  

35
150
825
270
240
25
更新
那是我的密码

local function getChild(xml, name)
    for i=1,#xml.ChildNodes do
    if xml.ChildNodes[i].Name == name then
    return xml.ChildNodes[i]
    end
    end
    end

    -- helper function to get all children of xml node by name
    local function getChildren(xml, name)
    local result = {}
    for i=1,#xml.ChildNodes do
    if xml.ChildNodes[i].Name == name then
    result[#result + 1] = xml.ChildNodes[i]
    end
    end
    return result
    end

    info = gideros.class(Sprite)
    if info.innerSprite ~= nil then
    info:removeChild(self.innerSprite)
    end
    info.innerSprite = Sprite.new()
    info.innerSprite:setPosition(200, 10)

    local font = TTFont.new("Roboto-Regular.ttf", 38)
    local small_font = TTFont.new("Roboto-Regular.ttf", 30)

    function info:init()    
    local xml = XmlParser:ParseXmlFile("header.xml")
    local layout = getChild(xml, "layout")
    local filepath = getChildren(layout, "file:path")   

    local logo = Bitmap.new(Texture.new("logo.png"))
    self:addChild(logo)
    logo:setPosition(780, 5)    

    local Update_Btn = Bitmap.new(Texture.new("Update_Btn.png"))
    self:addChild(Update_Btn)
    Update_Btn:setPosition(33, 23)  
    Update_Btn:addEventListener(Event.MOUSE_DOWN, 
    function()  
    -- Get source
    local src_bio = {}
    local src_image = {}
    for i = 1, #filepath do
    table.insert(src_bio, filepath[i].Attributes["bio"])
    table.insert(src_image, filepath[i].Attributes["image"])
    end

    -- Check if file exist
    for i = 1, #filepath do
    local bio_file = io.open(src_bio[i]) 
    local image_file = io.open(src_image[i])
    if (bio_file == nil or image_file == nil) then
    table.remove(src_bio, i)
    table.remove(src_image, i)
    else
    bio_file:close()
    image_file:close()
    end
    end

    -- Get content
    local tbInfo_List = {}
    for i = 1, #src_bio do
    tbInfo_List[i] = {}
    local tbInfo_tmp1 = ReadFile(src_bio[i])
    local tbInfo_tmp2 = ConvertTable(tbInfo_tmp1)
    table.insert(tbInfo_List[i], tbInfo_tmp2)
    end

    -- Fill content
    local xml_layout_x = getChild(layout, "layout_x") *=> the error is HERE* 
    local layout_x = xml_layout_x.Value
    local xml_layout_y = getChild(layout, "layout_y")
    local layout_y = xml_layout_y.Value
    local xml_layout_width = getChild(layout, "layout_width")
    local layout_width = xml_layout_width.Value

    for i = 1, #tbInfo_List do
    local tmp_y = layout_y + layout_width*(i - 1) + 25
    table.insert(tbInfo_List[i], src_image[i])
    CreateInformationTag(layout_x, tmp_y, tbInfo_List[i], layout)   
    end
    end
    )

    local Exit_Btn = Bitmap.new(Texture.new("Exit_Btn.png"))
    self:addChild(Exit_Btn)
    Exit_Btn:setPosition(397, 23)
    Exit_Btn:addEventListener(Event.MOUSE_DOWN, 
    function()
    sceneManager:changeScene("home", 1, transition, easing.outBack)
    end
    )
    end

    local function CreateInformationTag(x,y, tbInfo, layout)    
    local image = Bitmap.new(Texture.new(tbInfo.image))
    local name = tbInfo.name
    local born = tbInfo.born
    local weight = tbInfo.weight
    local bio = tbInfo.bio

    --Add Image
    image.setPosition(x, y)
    self.innerSprite.addChild(image)

    local xml_image = getChild(layout, "image")
    local xml_image_width = getChild(layout, "width")
    local image_width = xml_image_width.Value()
    local xml_table = getChild(layout, "table")
    local xml_table_layout_x = getChild(xml_table, "layout_x")
    local table_layout_x = xml_table_layout_x.Value()

    local xml_table_row = getChild(xml_table, "tablerow")
    local tbTextView = {}

    -- .Name
    local xml_table_row_textview_name = getChild(xml_table_row, "textview_name")
    table.insert(tbTextView, xml_table_row_textview_name.Value())
    -- .Born
    local xml_table_row_textview_born = getChild(xml_table_row, "textview_born")
    table.insert(tbTextView, xml_table_row_textview_born.Value())
    -- .Weight
    local xml_table_row_textview_weight = getChild(xml_table_row, "textview_weight")
    table.insert(tbTextView, xml_table_row_textview_weight.Value())
    -- .Bio
    local xml_table_row_textview_bio = getChild(xml_table_row, "textview_bio")
    table.insert(tbTextView, xml_table_row_textview_bio.Value())

    local table_x = x + image_width + table_layout_x
    local table_y = y
    local table_offset_y = 20

    -- Add label
    for i = 1, 4 do
    local textfield = TextField.new(font, tbTextView[i])    
    local tmp_y = table_y + (i - 1)*table_offset_y 
    textfield:setPosition(table_x, tmp_y)
    self.innerSprite:addChild(textfield)
    end

    -- Add text box
    local edittext_name_offset_x = getChild(xml_table_row, "edittext_name_offset_x")
    local name_offset_x = edittext_name_offset_x.Value() 
    local edittext_name_width = getChild(xml_table_row, "edittext_name_width")
    local name_width = edittext_name_width.Value() 
    local edittext_name_height = getChild(xml_table_row, "edittext_name_height")
    local name_height = edittext_name_height.Value() 

    -- Draw text box
    for i = 1, 3 do
    local line = Shape.new()
    local tmp_y = table_y + table_offset_y*(i - 1)
    line:setLineStyle(5, 0x000000, 1)
    line:beginPath()
    line:moveTo(table_x + edittext_name_x,tmp_y)
    line:lineTo(table_x + edittext_name_x + name_width, tmp_y)
    line:lineTo(table_x + edittext_name_x + name_width, tmp_y + name_height)
    line:lineTo(table_x + edittext_name_x, tmp_y + name_height)
    line:lineTo(table_x + edittext_name_x, tmp_y)
    line:endPath()  
    self.innerSprite:addChild(line)
    end

    -- Draw bio text box
    local edittext_bio_width = getChild(xml_table_row, "edittext_bio_width")
    local bio_width = edittext_bio_width.Value() 
    local edittext_bio_height = getChild(xml_table_row, "edittext_bio_height")
    local bio_height = edittext_bio_height.Value() 

    local line_bio = Shape.new()
    line_bio:setLineStyle(5, 0x000000, 1)
    line_bio:beginPath()
    line_bio:moveTo(table_x + edittext_name_x,tmp_y)
    line_bio:lineTo(table_x + edittext_name_x + bio_width, tmp_y)
    line_bio:lineTo(table_x + edittext_name_x + bio_width, tmp_y + bio_height)
    line_bio:lineTo(table_x + edittext_name_x, tmp_y + bio_height)
    line_bio:lineTo(table_x + edittext_name_x, tmp_y)
    line_bio:endPath()  
    self.innerSprite:addChild(line_bio)

    -- Add text in box
    for i = 1, 3 do
    local textfield = TextField.new(small_font, tbInfo[i])  
    local tmp_y = table_y + (i - 1)*table_offset_y 
    textfield:setPosition(table_x, tmp_y)
    self.innerSprite:addChild(textfield)
    end

    -- Add wrap text
    local tw = TextWrap2.new(tbInfo[4], table_x, table_y + 2*table_offset_y , 18, small_font)
    self.innerSprite:addChild(tw)
    end


    function ReadFile(filename)
    local tbInfo = {}
    fp = io.open(filename, "r")

    for line in fp:lines() do
    table.insert(tbInfo, line)
    end 
    fp:close()
    return tbInfo
    end

    function ConvertTable(tbInfo)
    local tmp = {}
    for i = 1, #tbInfo do
    if (i <= 4) then<br />   table.insert(tmp, tbInfo[i])
    else
    local str1 = tmp[5]
    local str2 = tbInfo[i]
    table.remove(tmp, 5)
    local str = str1 + str2
    table.insert(tmp, str)
    end
    end
    return tmp
    end
local函数getChild(xml,name)
对于i=1,#xml.ChildNodes
如果xml.ChildNodes[i].Name==Name,则
返回xml.ChildNodes[i]
结束
结束
结束
--helper函数,用于按名称获取xml节点的所有子节点
本地函数getChildren(xml,名称)
局部结果={}
对于i=1,#xml.ChildNodes
如果xml.ChildNodes[i].Name==Name,则
结果[#结果+1]=xml.ChildNodes[i]
结束
结束
返回结果
结束
info=gideros.class(精灵)
如果info.innerSprite~=nil,则
信息:removeChild(self.innerSprite)
结束
info.innerSprite=Sprite.new()
innerSprite信息:设置位置(200,10)
本地字体=TTFont.new(“Roboto Regular.ttf”,38)
本地小字体=TTFont.new(“Roboto Regular.ttf”,30)
函数信息:init()
local xml=XmlParser:ParseXmlFile(“header.xml”)
本地布局=getChild(xml,“布局”)
本地filepath=getChildren(布局,“文件:路径”)
本地logo=Bitmap.new(Texture.new(“logo.png”))
self:addChild(徽标)
徽标:设置位置(780,5)
本地更新\u Btn=Bitmap.new(Texture.new(“更新\u Btn.png”))
self:addChild(更新\u Btn)
更新:设置位置(33,23)
更新\u Btn:addEventListener(Event.MOUSE\u向下,
函数()
--获取来源
局部src_bio={}
本地src_映像={}
对于i=1,#filepath do
表.insert(src_bio,文件路径[i]。属性[“bio”])
表.insert(src_图像,文件路径[i]。属性[“图像”])
结束
--检查文件是否存在
对于i=1,#filepath do
本地bio_file=io.open(src_bio[i])
本地映像\u文件=io.open(src\u映像[i])
如果(bio_file==nil或image_file==nil),则
表.删除(src_bio,i)
表.删除(src_图像,i)
其他的
bio_文件:关闭()
图像_文件:关闭()
结束
结束
--得到满足
本地tbInfo_列表={}
对于i=1,#src#u bio do
tbInfo_列表[i]={}
本地tbInfo_tmp1=ReadFile(src_bio[i])
本地tbInfo_tmp2=可转换表(tbInfo_tmp1)
表.插入(tbInfo\U列表[i],tbInfo\U tmp2)
结束
--填充内容
本地xml\u layout\u x=getChild(layout,“layout\u x”)*=>错误在这里*
本地布局\u x=xml\u布局\u x.Value
本地xml\u layout\u y=getChild(布局,“布局y”)
本地布局\u y=xml\u布局\u y.Value
本地xml\u layout\u width=getChild(布局,“布局宽度”)
本地布局\u宽度=xml\u布局\u宽度.Value
对于i=1,#tbInfo_List do
本地tmp_y=布局_y+布局_宽度*(i-1)+25
表.插入(tbInfo\U列表[i],src\U图像[i])
CreateInformationTag(布局x、tmp、tbInfo列表[i],布局)
结束
结束
)
本地Exit_Btn=Bitmap.new(Texture.new(“Exit_Btn.png”))
self:addChild(退出\u Btn)
出口:设置位置(397,23)
Exit_Btn:addEventListener(Event.MOUSE_向下,
函数()
场景管理员:改变场景(“家”,1,过渡,放松,内陆)
结束
)
结束
本地函数CreateInformationTag(x、y、tbInfo、布局)
局部图像=位图.new(纹理.new(tbInfo.image))
本地名称=tbInfo.name
本地出生=tbInfo.born
本地重量=tbInfo.weight
本地bio=tbInfo.bio
--添加图像
图像。设置位置(x,y)
self.innerSprite.addChild(图像)
本地xml_image=getChild(布局,“图像”)
本地xml\u图像\u宽度=getChild(布局,“宽度”)
本地图像\u width=xml\u图像\u width.Value()
本地xml_table=getChild(布局,“表”)
本地xml\u表\u布局\u x=getChild(xml\u表,“布局\u x”)
本地表\u布局\u x=xml\u表\u布局\u x.Value()
本地xml_表_行=getChild(xml_表,“tablerow”)
本地tbTextView={}
--.姓名
本地xml\u表\u行\u文本视图\u名称=getChild(xml\u表\u行,“文本视图\u名称”)
table.insert(tbTextView,xml\u table\u row\u textview\u name.Value())
--.出生
本地xml\u表\u行\u文本视图\u出生=getChild(xml\u表\u行,“文本视图\u出生”)
table.insert(tbTextView,xml\u table\u row\u textview\u born.Value())
--.重量
本地xml\u表\u行\u文本视图\u权重=getChild(xml\u表\u行,“文本视图\u权重”)
table.insert(tbTextView,xml\u table\u row\u textview\u weight.Value())
--.生物
本地xml\u table\u row\u textview\u bio=getChild(xml\u table\u row,“textview\u bio”)
table.insert(tbTextView,xml\u table\u row\u textview\u bio.Value())
本地表格\u x=x+图像\u宽度+表格\u布局\u x
本地表_y=y
本地表偏移量y=20
--添加标签
对于i=1,则为4
本地textfield=textfield.new(字体,tbTextView[i])
本地tmp_y=表_y+(i-1)*表_偏移量_y
文本字段:设置位置(表x、tmp\U y)
self.innerSprite:addChild(textfield)
结束
--添加文本框
本地edittext\u name\u offset\u x=getChild(xml\u table\u行,“edittext\u name\u offset\u x”)
本地名称\u offset\u x=edittext\u name\u offset\u x.Value()
本地edittext\u name\u width=getChild(xml\u table\u行,“edittext\u name\u width”)
本地名称\u宽度=编辑文本\u名称\u宽度.Value()
本地edittext\u name\u height=getChild(xml\u table\u行,“edittext\u name\u height”)
本地名称\高度=编辑文本\名称\高度.Value()
--绘制文本框
对于i=1,则为3
局部线=Shape.new()
本地tmp_y=表_y+表_偏移量_y*(i-1)
行:setLineStyle(50x000000,1)
行:beginPath()
行:移动到(表\u x+编辑文本\u名称\u x,tmp\u y)
行:行到(表x+edittext\u名称x+name\u宽度,tmp\u y)
line:lineTo(表格x+edittext\u名称x+name\u宽度、tmp\u y+name\u高度)
line:lineTo(表格x+edittext\U名称x、tmp\U y+名称\U高度)
行:行到(表x+edittext\u名称x,tmp\u y)
行:endPath()
self.innerSprite:addChild(行)
结束
--画报