Openresty installation and use of LuaXml

  openresty

Install LuaXml

downloadluaxml
Then modify Makefile

# 2009-03-16 by gf

# generic compiler and linker settings:
CC     = gcc
INCDIR = -I/usr/local/openresty/luajit/include/luajit-2.1
LIB    = 
LIBDIR =  -L. -L/usr/local/openresty/luajit/lib
CFLAGS = -Os -Wall -c #-g

# generic platform specific rules:
ARCH            = $(shell uname -s)
ifeq ($(ARCH),Linux)
  CFLAGS += -fPIC
  LFLAGS =  -fPIC -shared
  LIBS          = $(LIBDIR) $(LIB) -lluajit-5.1 -ldl
  EXESUFFIX =
  SHLIBSUFFIX = .so

else  
  ifeq ($(ARCH),Darwin) # MacOSX
    LFLAGS = -bundle 
    LIBS          = $(LIBDIR) -L/usr/local/lib $(LIB) -lluajit-5.1
    EXESUFFIX = .app
    SHLIBSUFFIX = .so
    
  else  # windows, MinGW
    LFLAGS =  -shared
    LIBS          = $(LIBDIR) $(LIB) -llua51 -mconsole -s
    EXESUFFIX = .exe
    SHLIBSUFFIX = .dll

  endif
endif

# project specific targets:
all:  LuaXML_lib$(SHLIBSUFFIX)

# project specific link rules:
LuaXML_lib$(SHLIBSUFFIX): LuaXML_lib.o
    $(CC) -o $@ $(LFLAGS) $^ $(LIBS) 

# project specific dependencies:
LuaXML_lib.o:  LuaXML_lib.c

# generic rules and targets:
.c.o:
    $(CC) $(CFLAGS) $(INCDIR) -c $<
clean:
    rm -f *.o *~ LuaXML_lib.so LuaXML_lib.dll

The main changes are as follows:

INCDIR = -I/usr/local/openresty/luajit/include/luajit-2.1
LIBDIR =  -L. -L/usr/local/openresty/luajit/lib
LIBS          = $(LIBDIR) $(LIB) -lluajit-5.1 -ldl
LIBS          = $(LIBDIR) -L/usr/local/lib $(LIB) -lluajit-5.1
LIBS          = $(LIBDIR) $(LIB) -llua51 -mconsole -s

Copy to openresty/openresty: 1.11.2.1-trusty mirror instance, and then compile on this basis.

make clean && make

Then copy LuaXML_lib.so and LuaXml.lua /usr/local/openresty/lualib/

Use luaxml

    require "LuaXml"
    xml = require "xml"
    local resp = xml.eval(xmlStr)
    local oktag = resp:find("ok")
    local ok = oktag[1]
    ngx.log(ngx.INFO,"ok tag:"..ok)
  • About xml
    If you do not require “xml “but use xml directly, the second request will report an error.

attempt to index global 'xml' (a nil value)    
  • About eval
    The return is lua table, which comes out through find and is also a table. if it is a single value, take the first one of the array, such as xmlStr is

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<result>
<ok>false</ok>
</result>

doc