libxml2#
local xml = require 'libxml2'
The libxml2
module is, as its name suggests, a Lua binding to
libxml2.
Functions#
- libxml2.read_file(path)#
Read xml from
path
and parse into an XML document.Important
Parsing errors are printed to the log. In some cases parsing will continue, but in others parsing will fail in which case this function. returns
nil
.Version History
Version
Notes
0.0.1
Added
- libxml2.read_string(xml, name[, callbacks])#
Parse xml from
xml
. Ifcallbacks
are supplied SAX based parsing can be performed. The following fields will be called if they exist oncallbacks
:Field/Function
Description
startelement
Called at an opening element with the element name, a table of attributes, the name of the current document, and the current line this element occurs on.
local function startelement(name, attrs, doc, line) end
endelement
Called at a closing element with the element name, the name of the current document, and the current line.
local function endelement(name, doc, line) end
Important
Parsing errors are printed to the log. In some cases parsing will continue, but in others parsing will fail in which case this function. returns
nil
.- Parameters:
- Return type:
Version History
Version
Notes
0.0.1
Added
0.1.0
Added callbacks parameter, SAX2 parsing
Classes#
- class libxml2.XMLDoc#
An XML Document.
- get_root_element()#
Return the root element for this document.
- Return type:
Version History
Version
Notes
0.0.0
Added
- name()#
Return the name of this document. This is the name supplied with
read_string()
.- Return type:
Version History
Version
Notes
0.0.1
Added
- class libxml2.XMLNode#
A node within a
XMLDoc
. This could be an element with children, a text node, whitespace or comment.- prev()#
Return the previous sibling of this node. In other words, the node that appears before this one in its parent’s children.
This function will return
nil
if there is no previous sibling.- Return type:
Version History
Version
Notes
0.0.1
Added
- next()#
Return the next sibling of this node. In other words, the node that appears after this one in its parent’s children.
This function will return
nil
if there is no next sibling.- Return type:
Version History
Version
Notes
0.0.1
Added
- children()#
Return the first child of this node. The
prev()
andnext()
methods of that node can be used to traverse all child nodes.This function will return
nil
if this node has no children.- Return type:
Version History
Version
Notes
0.0.1
Added
- type()#
Return a string indicating the type of this node. One of:
element-node
attribute-node
text-node
cdata-section-node
entity-ref-node
pi-node
comment-node
document-node
document-type-node
document-fragment-node
notation-node
html-document-node
dtd-node
element-declaration
attribute-declaration
entity-declaration
namespace-declaration
xinclude-start
xinclude-end
unknown
- Return type:
Version History
Version
Notes
0.0.1
Added
- name()#
Return the name of this node. For element nodes, this will be the tag name.
nil
is returned if the node does not have a name.- Return type:
Version History
Version
Notes
0.0.1
Added
- prop(name[, value])#
Return or set the value of a property (attribute) on this node.
If
value
is omitted, the value ofname
property is returned.If
value
is omitted andname
does not exist on this node,nil
is returned.- Parameters:
- Return type:
Version History
Version
Notes
0.0.1
Added
- props()#
Return a sequence of property names on this node.
- Return type:
Version History
Version
Notes
0.0.1
Added
- content([text])#
Return or set the content of this node. If
text
is omitted, the content is returned, otherwise the content is set totext
- Return type:
Version History
Version
Notes
0.0.1
Added