LuaXPath
LuaXPath: Simple XPath implementation in the Lua programming language
home · introduction · usage · examples · related docs

Introduction

LuaXPath is a simple provides a very Lua library that implements XPath technology.

It enables a Lua program to fetch parts of an XML using xpath expressions.

LuaXPath is based on LuaExpat and on Lua 5.1.

Usage

require "xpath"
local lom = require "lxp.lom"

xpath.selectNodes(lom.parse(xmlString),xpathExpression)

Examples

require "xpath"
local lom = require "lxp.lom"

local xmlTest =
[[
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
	<element id="1" name="element1">text of the first element</element>
        <element id="2" name="element2">
		<subelement>text of the second element</subelement>
        </element>
</root>
]]

-- get all elements
xpath.selectNodes(lom.parse(xmlTest),'//element')
-- get the subelement text
xpath.selectNodes(lom.parse(xmlTest),'/root/element/subelement/text()')
-- get the first element
xpath.selectNodes(lom.parse(xmlTest),'/root/element[@id="1"]')

Related documentation

Here is a list of related documentation:
home · introduction · usage · examples · related docs