lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello,

Here is yet another XML pull parser of sort. Nothing fancy. Just enumerate through all the tags.

Usage example:

local anInputStream = LUXMLInputStream.new( aContent )

while ( true ) do
local aType, aContent, aName, someAttributes = anInputStream.read()

        if ( aType == nil ) then
                break
        elseif ( aType == LUXMLInputStream.Text ) then
                print( aType, aContent )
        elseif ( someAttributes ~= nil ) then
print( aType, aName, someAttributes.keys().sort().toString() )
        else
                print( aType, aName )
        end
end

Each call to the read() method returns 4 values:

- The type of the tag (either Tag, EndTag, Text or nil)
- The tag content (either the tag itself or the text)
- The tag name if any
- The tag attributes if any

Here is an output sample of the above code for http://www.lua.org/

1       HTML
1       HEAD
1       TITLE
3       The Programming Language Lua
2       TITLE
1       LINK    { "HREF", "REL", "TYPE" }
1       META    { "CONTENT", "NAME" }
1       META    { "CONTENT", "NAME" }
2       HEAD
1       BODY
1       HR
1       CENTER
1       H1
1       IMG     { "ALT", "SRC" }

http://dev.alt.textdrive.com/file/lu/LUXMLInputStream.lua

Cheers

--
PA, Onnay Equitursay
http://alt.textdrive.com/