I'm using LuaXML to parse an XML file. I'm using the example found in the LuaXML repository to test out the library, right now I'm simply putting my file through the parser like so:
local filename = "dir/myxml.xml"
local xmltext = ""
local f, e = io.open(filename, "r")
if f then
--Gets the entire file content and stores into a string
xmltext = f:read("*a")
else
error(e)
end
--Instantiate the object the states the XML file as a Lua table
local xmlhandler = simpleTreeHandler()
--Instantiate the object that parses the XML to a Lua table
local xmlparser = xmlParser(xmlhandler)
xmlparser:parse(xmltext)
For the example file and another example I found online the code works perfectly. However, for the file I want to parse I get the following error:
...dir/LuaXML/xml.lua:170: XMLDecl not at start of document [char=1]
My interpretation is that the XML declaration is not correct, but the very first line of the XML file is:
<?xml version="1.0" encoding="utf-8"?>
Which is the same/similar to the examples. Also, there is no whitespace before the first line.
Thanks!
It turns out this error is due to the BOM. To correct it I opened my XML file in Notepad++ and then did the following
Encoding --> Encode in UTF-8.
When I reran my program I got no errors.