xmlparser
is a XML parser written entirely in Lua 5.
This implementation is limited and extracts only valid entities, attributes and tags (without CDATA).
For a faster parser with more features, look at lua-xmllpegparser.
luarocks install --local https://raw.githubusercontent.com/jonathanpoelen/lua-xmlparser/master/xmlparser-2.2-3.rockspec
# Or in your local lua-xmlparser directory
luarocks make --local xmlparser-2.2-3.rockspec
Run ./example.lua
.
./example.lua [xmlfile [replaceentities]]
replaceentities
= anything, only to enable replacement of entities.
xmlparser.parse(xmlstring[, evalEntities])
: Return a documenttable
(see below). IfevalEntities
istrue
, the entities are replaced and atentity
member is added to the documenttable
.xmlparser.parseFile(filename[, subEntities])
: Return a tupledocument table, error file
.xmlparser.defaultEntitiyTable()
: Return the default entity table ({ quot='"', ... }
).xmlparser.createEntityTable(docEntities[, resultEntities])
: Create an entity table from the document entity table. ReturnresultEntities
.xmlparser.replaceEntities(s, entityTable)
: Return astring
.
document = {
children = {
{ text=string } or
{ tag=string,
attrs={ [name]=value ... },
orderedattrs={ { name=string, value=string }, ... },
children={ ... }
},
...
},
entities = { { name=string, value=string }, ... },
tentities = { name=value, ... } -- only if evalEntities = true
}
- Non-validating
- No DTD support
- No CDATA support
- Fails to detect any errors
- Ignore processing instructions
- Ignore DOCTYPE, parse only ENTITY