Internationalisation
Bundled Plugins API
xml
Functions for Generating XML markup.
This library allows the creation of 'safe' XML using via code.
Examples:
1
local xml = require "cp.web.xml"
2
print xml.Root "Hello world!" -- "<Root>Hello world!</Root>"
3
print xml.Root { class = "custom" } "Hello world!" -- "<Root class='custom'>Hello world!</Root>"
4
print xml.Root { class = "custom" } (
5
xml.Child "One" .. " and " .. xml.Child "Two" .. "."
6
)
7
-- "<Root class='custom'><Child>One</Child> and <Child>Two</Child>.</Root>"
8
print xml("1 < 2") -- "1 &lt; 2" (escaped)
9
print xml("1 < 2", true) -- "1 < 2" (unescaped)
10
print xml.Root ("<Child>One</Child>", true) -- "<Root><Child>One</Child></Root>"
Copied!
Be aware that concatonating with ".." can behave unexpectedly in some cases. For example:
1
local name = "world!"
2
print xml.Root "Hello " .. name -- "<Root>Hello </Root>world!"
Copied!
The "Hello" gets inserted into the Root tag, but the name gets concatonated after the closing tag. To get the name inside the Root tag, we need to put brackets around the content:
1
print xml.Root ("Hello " .. name) -- "<Root>Hello world!</Root>"
Copied!
Any tag name can be generated, along with any attribute. The results are correctly escaped. There are two 'special' tag names:
  • CDATA - will generate a &lt;![CDATA[ ... ]]&gt; section with the content contained.
  • __ - (double underscore) will generate a &lt!-- ... --&gt comment block.

API Overview

  • Functions - API calls offered directly by the extension
  • is

API Documentation

Functions

is

Signature
cp.web.xml.is(value) -> boolean
Type
Function
Description
Checks if the value is an cp.web.xml block.
Parameters
  • value - the value to check
Returns
  • true if it is an HTML block, or false otherwise.
Last modified 1mo ago
Export as PDF
Copy link