Module expadom.xmlutils

XML utility functions

Functions

escape (str) Escapes a string for safe use in xml.
qualifiedname (localname, prefix) creates a qualified name (without validation).
split_name (name) splits a (qualified) name in a prefix + localname (without validation).
validate_name (name) validates a non-qualified name.
validate_prefix (name) validates a prefix.
validate_qualifiedName_and_uri (qualifiedName, namespaceURI) validates a qualified name and its URI.
validate_qualifiedname (qualifiedName) validates a qualified name.

Tables

utf8 Library for UTF-8 support.


Functions

escape (str)
Escapes a string for safe use in xml. Handles quotes(single+double), less-than, greater-than, and ampersand.

Parameters:

  • str string string value to escape

Returns:

    escaped string

Usage:

    local esc = xml.xml_escape([["'<>&]])  --> "&quot;&apos;&lt;&gt;&amp;"
qualifiedname (localname, prefix)
creates a qualified name (without validation). if prefix is either empty or nil, the prefix is omitted

Parameters:

  • localname string the localname
  • prefix string or nil the prefix

Usage:

    local qualified = qualifiedname("orange", "clr")  --> "clr:orange"
    local qualified = qualifiedname("orange", "")     --> "orange"
    local qualified = qualifiedname("orange")         --> "orange"
split_name (name)
splits a (qualified) name in a prefix + localname (without validation).

Parameters:

  • name string the tag/attribute name, with or without namespace prefix

Returns:

    localname, prefix. Prefix will be 'nil' if there was none

Usage:

    local name, prefix = split_name("clr:orange")  --> "orange", "clr"
    local name, prefix = split_name("orange")      --> "orange", nil
validate_name (name)
validates a non-qualified name. must be a string, at least 1 character

Parameters:

  • name string the tag/attribute name

Returns:

    name, or nil+err
validate_prefix (name)
validates a prefix. must be a string, can be 0 length

Parameters:

Returns:

    name or nil+err
validate_qualifiedName_and_uri (qualifiedName, namespaceURI)
validates a qualified name and its URI. namespaceURI can be nil, if there is no prefix in the qualified name. If the prefix is xml then the namespace must be http://www.w3.org/XML/1998/namespace.

Parameters:

  • qualifiedName string the tag/attribute name, with or without namespace prefix
  • namespaceURI string or nil the namespace uri

Returns:

    localname, prefix, uri, or nil+err. Prefix will be 'nil' if there was none.
validate_qualifiedname (qualifiedName)
validates a qualified name. must be a string, localname and prefix at least 1 character

Parameters:

  • qualifiedName string the tag/attribute name, with or without namespace prefix

Returns:

    localname, prefix. Prefix will be 'nil' if there was none.

Tables

utf8
Library for UTF-8 support. This is either the stock Lua lib, on Lua 5.3 or higher. Or the one from the Lua 5.3 compatibility module; "compat53.utf8".
generated by LDoc 1.4.6 Last updated 2022-04-22 13:38:32