diff --git a/sample/parse-html.lua b/sample/parse-html.lua new file mode 100755 index 00000000..b083752c --- /dev/null +++ b/sample/parse-html.lua @@ -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 = [[ + + +

Hello

+ + +]] + +-- 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() -- --> element as xmlua.Element + +-- Prints root element name +print(root:name()) -- -> html