File size: 1,750 Bytes
7e9dc27 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
--[[------------------------------------------------------
# Parser object
The parser class is used to encapsulate parsing and settings in an object. When
using default settings, it is not necessary to create parser objects and
one can simply use [xml.load](xml.html#load).
--]]------------------------------------------------------
local core = require 'xml.core'
local lub = require 'lub'
local lib = core.Parser
-- ## Parser types
-- The following constants can be used with #new when creating a parser.
-- Depending on the type, the parser behavior is different. The default type is
-- Default.
-- Default parser type. Translates xml entities (needs to make an internal
-- copy of the lua string).
-- lib.Default
-- Same as default but trims leading and trailing whitespace.
-- lib.TrimWhitespace
-- Faster then default, does not translate xml entities. Parses data nodes.
-- lib.NonDestructive
-- Like xml.NonDestructive but does not parse data nodes.
-- lib.Fastest
-- Create a new parser. `type` flag is optional. If you are using the default
-- parser, you can simply use [xml.load](xml.html#load).
-- Usage example:
--
-- local xml = require 'xml'
-- local parser = xml.Parser(xml.Parser.Fastest)
-- function lib.new(type)
-- Parse an xml string and return a Lua table. See [lua/xml](xml.html)
-- for the format of the returned table. Usage:
--
-- local data = parser:load(some_xml_string)
-- --> lua table
-- function lib:load(str)
-- Parse xml from file `path` and return a Lua table. See [lua/xml](xml.html)
-- for the format of the returned table. Usage:
--
-- local data = parser:loadpath(path_to_file)
-- --> lua table
function lib:loadpath(path)
return self:load(lub.content(path))
end
return lib
|