Help us shape the future of Go! Take the 2026 Go Developer Survey

xmlpath

package
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2020 License: BSD-3-Clause Imports: 3 Imported by: 5

README

xmlpath GoDoc

Usage

local xmlpath = require("xmlpath")

local data = [[
<channels>
    <channel id="1" xz1="600" />
    <channel id="2"           />
    <channel id="x" xz2="600" />
</channels>
]]
local data_path = "//channel/@id"

-- xmlpath.load(data string)
local node, err = xmlpath.load(data)
if err then error(err) end

-- xmlpath.compile(path string)
local path, err = xmlpath.compile(data_path)
if err then error(err) end

-- path:iter(node)
local iter = path:iter(node)

for k, v in pairs(iter) do print(v:string()) end
-- Output:
-- 1
-- 2
-- x

Documentation

Overview

Package xmlpath provides xmlpath for lua.

Example (Full)

xmlpath.compile, xmlpath.load, xmlpath_node_ud, xmlpath_path_ud, xmlpath_iter_ud

state := lua.NewState()
Preload(state)
source := `
local xmlpath = require("xmlpath")

local data = [[
<channels>
    <channel id="1" xz1="600" />
    <channel id="2"           />
    <channel id="x" xz2="600" />
</channels>
]]
local data_path = "//channel/@id"

local node, err = xmlpath.load(data)
if err then error(err) end

local path, err = xmlpath.compile(data_path)
if err then error(err) end

local iter = path:iter(node)

for k, v in pairs(iter) do print(v:string()) end
`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:
1
2
x

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compile

func Compile(L *lua.LState) int

Compile lua xmlpath.compile(xpath string) return (xmlpath_path_ud, err)

func IterNode

func IterNode(L *lua.LState) int

IterNode lua xmlpath_iter_ud:node() returns node

func Load

func Load(L *lua.LState) int

Load lua xmlpath.load(xmlpath string) return (xmlpath_node_ud, err)

func Loader

func Loader(L *lua.LState) int

Loader is the module loader function.

func NodeToString

func NodeToString(L *lua.LState) int

NodeToString lua xmlpath_node_ud:string() returns string

func PathIter

func PathIter(L *lua.LState) int

PathIter lua xmlpath_path_ud:iter() returns table of nodes

func Preload

func Preload(L *lua.LState)

Preload adds xmlpath to the given Lua state's package.preload table. After it has been preloaded, it can be loaded using require:

local xmlpath = require("xmlpath")

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL