Skip to content

SetDefaultValue

Sets the value of the current node if it is empty.

1
myXml.SetDefaultValue(value: any):Array<Xml>

Sets the values of all nodes at the specified XPath if they are empty.

1
myXml.SetDefaultValue(xpath: string, value: any):Array<Xml>

Parameters

any value
    The value to update.

string xpath
    The XPath of the node to set. If not specified, the current node is used.

Returns

  • (value): An array that contains the current node.
  • (xpath, value): The nodes selected by the XPath, including nodes that already had a value.

Remarks

Nodes that already have a value are left unchanged, so the method is safe to call each time a script runs. Missing nodes are not created.

Examples

Fill a selected node only when it is empty

1
$Xml.SelectSingle('Customer/Name').SetDefaultValue('Unknown customer');

Fill empty values with defaults

1
2
$Xml.SetDefaultValue('DueDate', $Calendar.AddDays($Calendar.Today, 7));
$Xml.SetDefaultValue('Lines/Line/Quantity', 1);         // only empty quantities are set

See Also