メインコンテンツまでスキップ
バージョン:23.5

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.

ClosedSetting or Changing Global Property Values

You can set a global property value with the SenseTalk commands Set or Put. Note that when you reference one of these properties, you must use the word the before the property name to distinguish it from an ordinary variable.

Examples:

set the searchrectangle to [1,2,2,3]
put 2 into the remoteworkinterval

You can add or change specific named properties within a global property like this:

set the namedColors.pink to color("RGB,1.0,0.5,0.5") -- Adds pink to the namedColors global property and defines its RGB color value
set the listFormat's separator to " & " -- Sets the separator property of the listFormat global property

Properties can also be set or updated by using the setoption or setoptions commands. The setoption command lets you update a single property, and setoptions lets you update multiple properties.

Examples:

setoption searchrectangle, [1,2,2,3]
setoptions {searchrectangle: [1,2,2,3], scriptlogging: yes}
ノート

Because setoption and setoptions are specific for use with global and local properties, you omit the word the from the property name in the command syntax for these commands.

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: