Skip to content

Commit

Permalink
Add a sample to parse HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Nov 28, 2017
1 parent 033097a commit 22bf3e7
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions sample/parse-html.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env luajit

local xmlua = require("xmlua")

-- HTML to be parsed.
-- You may want to use HTML in a file. If you want to use HTML in a file,
-- you need to read HTML content from a file by yourself.
local html = [[
<html>
<body>
<p>Hello</p>
</body>
</html>
]]

-- Parses HTML
local success, document = pcall(xmlua.HTML.parse, html)
if not success then
local err = document
print("Failed to parse HTML: " .. err.message)
os.exit(1)
end

-- Gets the root element
local root = document:root() -- --> <html> element as xmlua.Element

-- Prints root element name
print(root:name()) -- -> html

0 comments on commit 22bf3e7

Please sign in to comment.