Global Properties for XML and Trees

SenseTalk includes two global properties that you can use to affect how your scripts interact with data in XML and tree structures.

For additional information about working with local and global properties, see Local and Global Properties in SenseTalk.

the treeFormat Global Property

Values: A property list with properties prettyPrint, compactEmptyElements, and useStandardFormat.

Default:

  • prettyPrint: True
  • compactEmptyElements: False

  • useStandardFormat: False

Behavior: PrettyPrint defines whether trees are displayed nicely formatted. Set this value to false to turn off pretty formatting of trees when they are displayed as XML text. The compactEmptyElements property controls the display of empty elements within the tree. If this property is set to False, empty nodes are displayed with the opening and closing elements separate. If the property is set to True, empty nodes are displayed in self-closing tags.

If the treeFormat's useStandardFormat property is set to true, trees are always converted to property lists using a standard format, with _tag, _attributes, and _children properties. When set to false, converting a tree into a property list (using as property list or as object) results in a simplified property list format being used for nodes that have a tag that is not a reserved property name or do not have any attributes that are reserved property names.

Example:

set the treeFormat's prettyPrint to false -- turn off tree indenting

set the treeFormat's compactEmptyElements to to true -- causes empty nodes to be displayed in self-closing tags

set the treeFormat's useStandardFormat to false -- allows the tree to be converted to a property list using the standard format

Example:

set OrderInfo to {{

<order id="001">

<quantity>5</quantity>

<price></price>

</order>

}}

set the treeFormat's compactEmptyElements to true

put OrderInfo as tree

The output for the above command would look something like the following:

<order id="001">

<quantity>5</quantity>

<price/>

</order>

Example:

put {{

<person id="007">

<name>James Bond</name>

</person>

}} into Person

set the treeFormat's prettyPrint to false

put person as tree //Displays 'James Bond'

Example:

set OrderInfo to {{

<order id="001">

<quantity>5</quantity>

<price></price>

</order>

}}

put OrderInfo as tree as object //Displays '(_attributes:(id:"001"), order:((quantity:(5)),(_tag:"price")))'

set the treeFormat's useStandardFormat to true

put OrderInfo as tree as object //Displays '(_attributes:(id:"001"), _children:((_children:((_text:"5")), _tag:"quantity"),(_tag:"price")), _tag:"order")'

Related:

the treeInputFormat Global Property

Values: A property list with property alwaysJoinText

Default: True

Behavior: The alwaysJoinText property defines whether text nodes are combined automatically whenever a change is made to a tree that results in two text nodes adjacent to each other. Setting it to false allows sequential text nodes to be present in trees, which might be useful for some applications but can prevent Xpath node access from working properly. Leave this value set to true to ensure that node access (using a node or all-nodes expression) works reliably.

Example:

set the treeInputFormat's alwaysJoinText to false

Related:

 

This topic was last updated on August 19, 2021, at 03:30:51 PM.

Eggplant icon Eggplantsoftware.com | Documentation Home | User Forums | Support | Copyright © 2022 Eggplant