Module "upnp.xmlfactory"

XML factory for generating device and service XML's which can be written to the webserver. This module has methods for creating service xmls and device xmls from Lua tables.

Functions

xmlfactory.rootxml (rootdev) Creates xml files for a root device, using the template engine.
xmlfactory.servicexml (service) Creates a service xml, using the template engine
xmlfactory.writetoweb (filelist) Writes the xmlfiles as received from xmlfactory.rootxml() to the webserver.


Functions

xmlfactory.rootxml (rootdev)
Creates xml files for a root device, using the template engine. The filenames generated are relative, so they should be placed relative to the webroot directory used.
NOTE: serviceId values will be updated with a trailing number if they are not unique within a device
NOTE: SCPDURL value for services will be set to the generated filenames

Parameters:

  • rootdev: the table with the rootdevice properties, its serviceList property should contain a list with all services defined as shown in the example code of xmlfactory.servicexml().

Return values:

  1. xml string containing the device xml
  2. table with 2 parts; array part is a list of filenames for the xmls (element 1 is the device xml filename), the hash part will hold the actual xml documents, indexed by their filenames.
xmlfactory.servicexml (service)
Creates a service xml, using the template engine

Parameters:

  • service: table with service parameters for the service xml to create

Example:

-- service table example
local service = {
  -- these two elements are not required for the service xml, but allow
  -- the same table to be used when creating a rootdevice xml
  serviceType = "urn:schemas-upnp-org:service:SwitchPower:1",
  serviceId = "urn:upnp-org:serviceId:myPowerSwitch",
  -- serviceId does not need to be unique, trailing numbering will
  -- automatically be added if needed.
  -- the SCPDURL, controlURL & eventSubURL will be set automatically
--
  -- The lists below are used for the service, every element named
  -- after its xml counterpart
  actionList = {
    { name = "switch",
      argumentList = {
        {
          name = "firstVal",
          direction = "in",
          relatedStateVariable = "firstVariable",
        },
        {
          name = "outVal",
          retval = true,
          direction = "out",
          relatedStateVariable = "firstVariable",
        },
      },
    },
  },
  serviceStateTable = {
    { name = "firstVal",
      evented = true,
      dataType = "number",
      defaultValue = "0",
      allowedValueRange = {
        minimum = 0,
        maximum = 100,
        step = 10,
      },
    },
    { name = "secondVal",
      evented = true,
      dataType = "string",
      defaultValue = "something",
      allowedValueList = { "something", "anything", "someone", "anyone" },
    },
  },
}
--
local xml = upnp.xmlfactory.servicexml(service)
xmlfactory.writetoweb (filelist)
Writes the xmlfiles as received from xmlfactory.rootxml() to the webserver.

Parameters:

  • filelist: list with filenames and file contents

Valid XHTML 1.0!