Chat freely about anything...

User avatar
By lakkimsetty
#20934 Hello guys.

I am new to lua and was working on NodeMCU. I was trying to extract data from an xml file.
Here is my xml file:
Code: Select all<?xml version="1.0" encoding="UTF-8"?>
<netconfig>
<mode>0</mode>
<stamac>18-FE-34-A4-4B-05</stamac>
<staip>XXX.XXX.XXX.XXX</staip>
<stanetmask>XXX.XXX.XXX.XXX</stanetmask>
<stagateway>XXX.XXX.XXX.XXX</stagateway>
<apmac>1A-FE-34-A4-4B-05</apmac>
<apip>192.168.4.1</apip>
<apnetmask>255.255.255.0</apnetmask>
<apgateway>192.168.4.1</apgateway>
<port>80</port>
<dns>XXX.XXX.XXX.XXX</dns>
<dhcp>1</dhcp>
<stacustomconfig></stacustomconfig>
<timezone>10</timezone>
<serial>0x00000001</serial>
<connssid>ESP-10767109</connssid>
<ssid></ssid>
<passwd></passwd>
<hostname>ESP-10767109</hostname>
<reboot></reboot>
<message></message>
</netconfig>


Here is my xmlparser:
Code: Select allreturn function (xmlfile, xmlword)
    file.open(xmlfile,"r")
    local eofflag = 0
    local i, j, k, l, xmloutput
    while(eofflag < 1) do
        local m = file.readline()
        if(m == nill) then
            eofflag = eofflag + 1
        elseif (string.find(m, xmlword) ~= nill) then
            i, j = string.find(m, xmlword, 1)
            i = i - 1
            j = j + 2
            k, l = string.find(m, xmlword, j)
            k = k - 3
            l = l + 1
            xmloutput = string.sub(m, j, k)
            eoffile = 1
        end
    end
    file.close()
    return xmloutput
end


I call this file by using:
Code: Select alllocal port = dofile("xmlparser.lc")("netconfig.xml", "port")


But I always endup with memory less than I started with even though I call the garbagecollector. Moreover The heap seems to decrease further if the word I am searching for is near the end of file. I also observed that if the word I am not looking for is not present, the heap has the less difference I started with.

Am I missing something? and thanks for taking a look.