[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: xml pull parser
- From: PA <petite.abeille@...>
- Date: Mon, 21 Mar 2005 12:00:12 +0100
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/