XML Techniques

Introduction

This example shows how to use the xml.lua module that contains several helpful xml utility functions.

If you have any questions please contact us at support@interfaceware.com.

Using the Code [top]

  • Import the XML Techniques channel from the Builtin: Iguana Protocols repository
  • Experiment with the code to find out how it works
  • Then add the module(s) to your Translator project
  • Copy the require statements from the channel and add them at the top of your script
    Note: The xml.lua module modifies the global namespace
    Note: The stringutil.lua module uses require to return a table
  • Adapt the code to your own requirements
  • Use node.text() to resolve the “Index X is out of bounds” error caused by trying to read an empty XML TEXT element
  • Use node.setText() to resolve the “Index X is out of bounds” error caused by trying to set an empty XML TEXT element
  • Use node.setText() to set a TEXT element to a space, instead of using node.setInner() which ignores the space and sets it to empty
  • Interactive scripting help is included for this module

This is the github code for the main module:

How it works [top]

When reading a TEXT element this module looks for the first TEXT element, and appends it if it does not exist. When setting a TEXT element or an ATTRIBUTE it also looks for the first instance and appends one if it does not exist.

This should work well in most cases, however If you need different behaviour then you must to use a different approach. See these pages for some alternative ideas: Set an XML node to a space ” ” character and Prevent errors reading from an empty XML element.

This module helps resolve some common issues that arise when working with XML node trees:

  • Use node.text() to resolve the “Index X is out of bounds” error caused by trying to read an empty XML TEXT element
  • Use node.setText() to resolve the “Index X is out of bounds” error caused by trying to set an empty XML TEXT element
  • Use node.setText() to set a TEXT element to a space, instead of using node.setInner() which ignores the space and sets it to empty

More information [top]

These functions are also documented in the CDA API guide:

Leave A Comment?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.