Qdabra Forms - qRules Command Guide Every qRules command, its parameters and behavior All manuals

Chapter 3 - Text, XML and JSON

First draft. This chapter has not been reviewed yet and may contain mistakes. Please read it with that in mind, and tell us about anything that does not match what you see.

These fifteen commands work on the content of fields rather than on the form's structure: read or write a node as an XML string, run an XSL transform, replace text, change case, join repeating values into a list, convert between JSON and XML, encode and decode text, copy and compare rich text, create GUIDs, and encrypt fields with a password. Chapter 1 explains the command syntax, dynamic parameter values and where results go; this chapter assumes you know it.

The examples use this main data source:

my:myFields
  my:Customer
    my:Name
    my:City
  my:Tags
    my:Tag                (repeating)
  my:Description          (rich text)
  my:Revisions
    my:Revision           (repeating)
      my:Before           (rich text)
      my:After            (rich text)
      my:Changes          (rich text)
  my:Payload              (text, holds JSON or XML)
  my:DocumentId
  my:ImportFile           (file attachment)
  my:ExportFile           (file attachment)
  my:Secret
  my:Password

3.1 GetXml

Returns the XML of a node as a string, with or without the node itself. Use it to store a snapshot of a group in a text field, to pass XML to a web service, or to let the user download a data source as an XML file.

Syntax

GetXml [/xpath=<XPath>] [/dsname=<data source>] [/inner=true] [/outer=true] [/download=true] [/filename=<name>]
Parameter Required Description
/xpath No The node to read. Default /, the whole data source. If several nodes match, the first is used.
/dsname No Data source. Omit for the main data source.
/inner No true returns only the node's content (its child nodes), without the node itself.
/outer No true returns the node itself with its content. This is the default. If both /inner and /outer are true, /outer wins.
/download No true also downloads the XML as a file. Default false.
/filename No File name for the download. Default: the /dsname value plus .xml; otherwise the name of the file the form was opened from, if any; otherwise document.xml.

Result: the XML string.

Examples

GetXml /xpath=/my:myFields/my:Customer
GetXml /xpath=/my:myFields/my:Customer /inner=true
GetXml /dsname=Settings /download=true

For a customer named Contoso in Seattle, the first returns <my:Customer><my:Name>Contoso</my:Name><my:City>Seattle</my:City></my:Customer> (with namespace declarations as needed), the second returns only the two child elements, and the third downloads the whole Settings data source as Settings.xml.

Notes

Related: SetXml, XmlToJson, Transform.

3.2 SetXml

Replaces the content of a node with XML given as a string. It is the counterpart of GetXml: restore a snapshot, load XML returned by a web service into a group, or build nodes from a text value.

Syntax

SetXml /destpath=<XPath> /value=<XML> [/destds=<data source>] [/excludesourceroot=true]
Parameter Required Description
/destpath Yes The node(s) whose content is replaced. Every selected node receives a copy of the XML.
/value Yes The XML to insert. Several top-level elements are allowed. Usually given with /value-xpath=.
/destds No Data source of the destination. Omit for the main data source.
/excludesourceroot No true inserts only the content of each top-level element of /value, not the element itself. Default false.

Result: empty on success.

Examples

SetXml /destpath=/my:myFields/my:Customer /value-xpath=/my:myFields/my:Payload /excludesourceroot=true

If Payload holds a copy of the my:Customer group taken with GetXml, this puts its Name and City back into the customer group. Without /excludesourceroot=true, a second my:Customer element would be created inside the existing one.

Notes

Related: GetXml, JsonToXml, Copy.

3.3 Transform

Runs an XSL transform (XSLT) on a node of any data source, or on an XML resource file, and stores the output in the form: as nodes under a destination node, as a text value, or as a file attachment. The XSLT is a resource file in the template. Use it for reshaping data that would take many rules otherwise. This command is for designers who can write XSLT.

Syntax

Transform /xsltfile=<resource file> [/sourcepath=<XPath>] [/sourceds=<data source> | /sourcefile=<resource file>] [/destpath=<XPath>] [/destds=<data source>] [/format=xml|string|base64] [/tostring=true] [/placement=replace|append|prepend] [/excluderoot=true] [/resultfilename=<name>] [/setresult=true]
Parameter Required Description
/xsltfile Yes Resource file name of the XSLT. It may use xsl:include and xsl:import to load other XSLT resource files.
/sourcepath No The node to transform. Default /, the whole source.
/sourceds No Data source of the source. Omit for the main data source.
/sourcefile No An XML resource file to use as the source instead of a data source. Cannot be combined with /sourceds.
/destpath No The node that receives the output. Default /; in practice always give it (see Notes). Only the first match is used.
/destds No Data source of the destination. Omit for the main data source.
/format No xml inserts the output as nodes (default). string stores the serialized output as the field's text. base64 stores it as a file attachment in the field. Lower case. Takes precedence over /tostring.
/tostring No true is the same as /format=string. Default false.
/placement No replace (default), append or prepend: replace the destination's content, or add after or before it. Not case-sensitive. Not used with base64.
/excluderoot No With xml: true inserts only the content of the output's root element, not the root itself.
/resultfilename With base64 File name of the attachment, for example summary.xml.
/setresult No true also returns the output as text in Result. Default false.
/usedocument No Accepted, but currently has no effect.

Result: empty, or the transform output as text when /setresult=true.

Examples

Transform /xsltfile=BuildSummary.xsl /sourcepath=/my:myFields/my:Revisions /destpath=/my:myFields/my:Payload /format=string
Transform /xsltfile=MapOrder.xsl /sourceds=OrderService /destpath=/my:myFields/my:Customer /excluderoot=true
Transform /xsltfile=Export.xsl /destpath=/my:myFields/my:ExportFile /format=base64 /resultfilename=export.xml

The first stores the transformed revisions as text in Payload. The second maps a web service response into the customer group; the XSLT outputs a wrapper element whose children are my:Name and my:City, and /excluderoot=true drops the wrapper. The third saves the transformed main data source as an attached file export.xml in a file attachment field.

Notes

Related: GetXml, SetXml.

3.4 ReplaceString

Replaces every occurrence of a text, or of a regular expression, in a field's value. In its basic form it returns the new text; with /reldest it writes the result into a field for every matching node, so one command can clean up a whole column.

Syntax

ReplaceString /xpathsrc=<XPath> /string1=<text> | /pattern=<regular expression> [/string2=<text>] [/dsnamesrc=<data source>] [/reldest=<relative XPath> [/append=true]]
Parameter Required Description
/xpathsrc Yes The field whose value is used. Single mode uses the first match; with /reldest every match is processed.
/string1 One of the two The text to replace. Case-sensitive, matched literally.
/pattern One of the two A regular expression (JavaScript syntax). Every match is replaced. Takes precedence over /string1.
/string2 No The replacement. Omit it to remove the found text. With /pattern, $1, $2 and so on insert the matched groups.
/dsnamesrc No Data source of /xpathsrc. Omit for the main data source.
/reldest No Turns on multi-node mode. XPath, relative to each source node, of the field that receives that node's result. Use . to write back into the source field itself.
/append No With /reldest: true appends the result to the destination's current value instead of replacing it.

Result: the new text (single mode), or the number of nodes processed (multi-node mode).

Examples

ReplaceString /xpathsrc=/my:myFields/my:Customer/my:Name /string1=Inc. /string2=Incorporated
ReplaceString /xpathsrc=/my:myFields/my:Tags/my:Tag /pattern=\s+ /string2=- /reldest=.
ReplaceString /xpathsrc=/my:myFields/my:Customer/my:City /pattern=^(\w+), (\w+)$ /string2=$2 $1

The first returns the name with "Inc." spelled out, leaving the field unchanged. The second replaces runs of white space with a hyphen in every tag, in place. The third swaps two comma-separated words.

Notes

Related: SetCase, SetValue.

3.5 SetCase

Returns a field's value in upper or lower case.

Syntax

SetCase /xpathsrc=<XPath> [/dsnamesrc=<data source>] [/case=Upper|Lower]
Parameter Required Description
/xpathsrc Yes The field to read. The first match is used.
/dsnamesrc No Data source. Omit for the main data source.
/case No Upper (default) or Lower. Case-sensitive: write the capital letter.

Result: the converted text. The field itself is not changed.

Example

SetCase /xpathsrc=/my:myFields/my:Customer/my:City /case=Upper /resultxpath=/my:myFields/my:Customer/my:City

Converts the city to capitals and writes it back into the same field with /resultxpath (see Chapter 1).

Notes

Related: ReplaceString.

3.6 DelimitedList

Joins the values of a repeating field, or of a field in a repeating group, into one text with a separator between them. Use it for a summary field, an e-mail recipient list or a filter value.

Syntax

DelimitedList /xpath=<XPath> [/dsname=<data source>] [/separator=<text>] [/space=before|after|both]
Parameter Required Description
/xpath Yes The fields whose values are joined, in document order.
/dsname No Data source. Omit for the main data source.
/separator No Text placed between the values. Default ;. Cannot be empty.
/space No Adds a space before, after or on both sides of the separator. Not case-sensitive.

Result: the joined text.

Examples

DelimitedList /xpath=/my:myFields/my:Tags/my:Tag /separator=, /space=after
DelimitedList /xpath=/my:myFields/my:Tags/my:Tag[. != '']

The first returns, for example, urgent, finance, review. The second returns urgent;finance;review and skips empty rows.

Notes

Related: GetValue.

3.7 JsonToXml

Converts a JSON string to XML and puts it under a node of a data source. Use it to work with the response of a JSON web API in rules, XPath and repeating tables.

Syntax

JsonToXml /xpath=<XPath> /json=<JSON> [/dsname=<data source>]
Parameter Required Description
/xpath Yes The element that receives the converted XML. The first match is used. Its existing content is replaced.
/json Yes The JSON text. Usually given with /json-xpath= (and /json-dsname=) from the field that holds it.
/dsname No Data source of the destination. Omit for the main data source.

Result: empty on success.

Example

JsonToXml /xpath=/Result /dsname=ApiResult /json-xpath=/my:myFields/my:Payload

If Payload holds {"name":"Contoso","id":5,"tags":["new","vip"]}, the Result element of the data source ApiResult becomes:

<Result type="object">
  <id type="number">5</id>
  <name type="string">Contoso</name>
  <tags type="array">
    <tagsItem type="string">new</tagsItem>
    <tagsItem type="string">vip</tagsItem>
  </tags>
</Result>

Notes

Related: XmlToJson, SetXml.

3.8 XmlToJson

Converts a node of a data source to a JSON string. Use it to build the body of a request to a JSON web API (for example with the MakeRequest command).

Syntax

XmlToJson [/xpath=<XPath>] [/dsname=<data source>]
Parameter Required Description
/xpath No The node to convert. The first match is used. Omit to convert the whole data source.
/dsname No Data source. Omit for the main data source.

Result: the JSON string.

Examples

XmlToJson /xpath=/my:myFields/my:Customer
XmlToJson /xpath=/my:myFields/my:Tags

The first returns {"Name":"Contoso","City":"Seattle"}. The second fails with a duplicate key error, because the repeating Tag elements become properties with the same name (see Notes).

Notes

Related: JsonToXml, GetXml.

3.9 Encode

Encodes or decodes text for use in a URL or in HTML.

Syntax

Encode /text=<text> [/type=url|uri|uriComponent|html] [/decode=true]
Parameter Required Description
/text Yes The text to encode or decode.
/type No url (default) and uri encode a complete URL: spaces and non-ASCII characters are encoded, but characters such as / ? & = # are kept. uriComponent encodes those characters too, for one value inside a URL. html replaces &, <, > and " with entities. Case-sensitive.
/decode No true decodes instead of encoding. Default false.

Result: the encoded or decoded text.

Examples

Encode /text-xpath=/my:myFields/my:Customer/my:Name /type=uriComponent
Encode /text-xpath=/my:myFields/my:Payload /type=html /decode=true

The first turns Smith & Sons into Smith%20%26%20Sons, safe for a query string value. The second turns &lt;b&gt; back into <b>.

Notes

Related: ConvertBase64.

3.10 ConvertBase64

Decodes a base64 value to text. It also accepts the value of a file attachment field and returns the content of the attached file as text, for example to read an attached XML, CSV or text file.

Syntax

ConvertBase64 /value=<base64> /mode=decode
Parameter Required Description
/value Yes The base64 value, or a file attachment value. Usually given with /value-xpath=.
/mode Yes decode, the only supported mode. Lower case.

Result: the decoded text.

Example

ConvertBase64 /value-xpath=/my:myFields/my:ImportFile /mode=decode /resultxpath=/my:myFields/my:Payload

Reads the file attached in ImportFile and puts its text into Payload.

Notes

Related: Encode, Transform.

3.11 CopyRichText

Copies the content of a rich text field into another rich text field, keeping its formatting, in the same or another data source.

Syntax

CopyRichText /xpathsrc=<XPath> /xpathdest=<XPath> [/dsnamesrc=<data source>] [/dsnamedest=<data source>]
Parameter Required Description
/xpathsrc Yes The rich text field to copy from. The first match is used.
/xpathdest Yes The rich text field to copy to. The first match is used. Its content is replaced.
/dsnamesrc No Data source of the source. Omit for the main data source.
/dsnamedest No Data source of the destination. Omit for the main data source.

Result: empty on success.

Example

CopyRichText /xpathsrc=/my:myFields/my:Description /xpathdest=/my:myFields/my:Revisions/my:Revision[last()]/my:Before

Copies the current description into the Before field of the last revision row.

Notes

Related: DiffRichText, Copy.

3.12 DiffRichText

Compares two rich text values and produces a rich text "track changes" view: inserted text is wrapped in <ins> and deleted text in <del>. It can compare one pair, or one pair in every row of a repeating group.

Syntax

DiffRichText /beforepath=<XPath> /afterpath=<XPath> [/dsname=<data source>] [/addstyles=true] [/implementation=dfoverdx|tnwinc]
DiffRichText /parentpath=<XPath> /beforepath=<relative XPath> /afterpath=<relative XPath> /destpath=<relative XPath> [/dsname=<data source>] [/addstyles=true] [/implementation=dfoverdx|tnwinc]
Parameter Required Description
/beforepath Yes The "before" rich text field. Relative to /parentpath when that is given.
/afterpath Yes The "after" rich text field. Relative to /parentpath when that is given.
/parentpath No The rows (or any nodes) to process. Each one is compared and its result written to /destpath.
/destpath With /parentpath Relative to /parentpath: the rich text field that receives the comparison.
/dsname No Data source of all the fields. Omit for the main data source.
/addstyles No true adds styles to the page that show insertions on a green and deletions on a red background. Default false.
/implementation No The comparison engine: dfoverdx (default) or tnwinc. Case-sensitive.

Result: without /parentpath, the comparison as HTML text. With /parentpath, empty.

Examples

DiffRichText /parentpath=/my:myFields/my:Revisions/my:Revision /beforepath=my:Before /afterpath=my:After /destpath=my:Changes /addstyles=true
DiffRichText /parentpath=/my:myFields /beforepath=my:Revisions/my:Revision[1]/my:After /afterpath=my:Description /destpath=my:Revisions/my:Revision[1]/my:Changes

The first fills Changes in every revision row with the marked-up differences and turns on the highlight colors. The second compares one pair and writes it into one rich text field, by using the common parent as /parentpath.

Notes

Related: CopyRichText.

3.13 GenerateGuid

Returns a new GUID (globally unique identifier). Use it for a unique document ID, a file name or a key for related records.

Syntax

GenerateGuid [/format=B|D|N|P]
Parameter Required Description
/format No D (default): with dashes. B: with dashes, in braces {...}. P: with dashes, in parentheses (...). N: 32 digits, no dashes. Not case-sensitive.

Result: the GUID.

Examples

GenerateGuid /resultxpath=/my:myFields/my:DocumentId
GenerateGuid /format=N

The first writes a GUID in the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx into DocumentId. The second returns the 32 digits without dashes.

Notes

Related: SetValue.

3.14 Encrypt

Encrypts the content of one or more fields with a password that the user types into another field. The value is replaced by encrypted text that can only be read again with Decrypt and the same password. Text, rich text and file attachment fields can be encrypted.

Syntax

Encrypt /xpath=<XPath> /pass=<XPath> [/dsnamepass=<data source>] [/clear=true|false] [/pad=true]
Parameter Required Description
/xpath Yes The field(s) to encrypt, in the main data source. Every selected field is encrypted.
/pass Yes XPath of the field that holds the password, not the password itself.
/dsnamepass No Data source of the password field. Omit for the main data source. Applies to /pass only.
/clear No Default true: the password field is emptied after the command. false keeps it.
/pad No true asks for padded encryption. Default false.

Result: empty on success.

Example

Encrypt /xpath=/my:myFields/my:Secret /pass=/my:myFields/my:Password

Encrypts Secret with the password in Password, then clears Password.

Notes

Related: Decrypt.

3.15 Decrypt

Restores fields encrypted with Encrypt, using the same password.

Syntax

Decrypt /xpath=<XPath> /pass=<XPath> [/dsnamepass=<data source>] [/clear=true|false]
Parameter Required Description
/xpath Yes The encrypted field(s), in the main data source. Every selected field is decrypted.
/pass Yes XPath of the field that holds the password.
/dsnamepass No Data source of the password field. Omit for the main data source. Applies to /pass only.
/clear No Default true: the password field is emptied after the command. false keeps it.

Result: empty on success.

Example

Decrypt /xpath=/my:myFields/my:Secret /pass=/my:myFields/my:Password /clear=false

Decrypts Secret and keeps the password in Password, for example to decrypt more fields with a later command.

Notes

Related: Encrypt.

Back to the Command Index.

© Qdabra Software  |  Questions and corrections: [email protected]  |  Preview copy, not linked from the public site.