Skip to content

Sync

Synchronizes specified xpath with input nodes and returns array of synchronized nodes.

1
myXml.Sync(xpath: string, input: Array<Xml>, hash: (node: Xml) => string):Array<Xml>

Synchronizes specified xpath with input nodes and returns array of synchronized nodes.

1
myXml.Sync(xpath: string, input: Array<Xml>, hash: (node: Xml) => string, removedNodes: Array<Xml>):Array<Xml>

Parameters

string xpath
    XPath of node to be append

Array<Xml> input
    Array of nodes to be synchronize

(node: Xml) => string hash
    Hash function to compare nodes. Can be omitted.

Array<Xml> removedNodes
    Instance of array to add removed nodes. Can be omitted.

Remarks

Synchornization is based on input nodes and performs following actions on specified xpath;
Node comparison done with specified hash function which returns unique identifier of node. If not specified uses the node instance.
Non-existing nodes on input auto created in current node.
Existing nodes in both values are copied.
Non-existing nodes on input are removed from current node. Optionally a list of removed nodes are added on "removedNodes" parameter.

Synchronize "Source" and "Target" node contents

1
2
3
4
var questions = $Xml.SelectAll('Source/Questions/Question');
$Xml.Sync('Target/Questions/Question', questions, function() {
  return this.Evaluate('Id');
});

Performs xquery and merges results with current nodes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
$Xml.SelectAll('Standards/Standard', function() {
  var questions = $XmlRepository.QueryXml('for $q in InternalAudit//Question\
    where $q/Standards/Standard/Standard=$standard and $q/Departments/Department=$department\
    return\
     <Question>\
        { $q/Id }\
        { $q/Criteria }\
        { $q/Expectation }\
     </Question>', {
     standard : this.Evaluate('Standard'),
     department : $Xml.Evaluate('Department')
  });
  this.Sync('Questions/Question', questions, function() {
    return this.Evaluate('Id');
  });
});

Synchronization is based on input nodes and performs following actions on specified xpath;
Node comparison done with specified hash function which returns unique identifier of node. If not specified uses the node instance.
Non-existing nodes on input auto created in current node.
Existing nodes in both values are copied.
Non-existing nodes on input are removed from current node. Optionally a list of removed nodes are added on "removedNodes" parameter.

Synchronize "Source" and "Target" node contents

1
2
3
4
var questions = $Xml.SelectAll('Source/Questions/Question');
$Xml.Sync('Target/Questions/Question', questions, function() {
  return this.Evaluate('Id');
});

Performs xquery and merges results with current nodes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
$Xml.SelectAll('Standards/Standard', function() {
  var questions = $XmlRepository.QueryXml('for $q in InternalAudit//Question\
    where $q/Standards/Standard/Standard=$standard and $q/Departments/Department=$department\
    return\
     <Question>\
        { $q/Id }\
        { $q/Criteria }\
        { $q/Expectation }\
     </Question>', {
     standard : this.Evaluate('Standard'),
     department : $Xml.Evaluate('Department')
  });
  this.Sync('Questions/Question', questions, function() {
    return this.Evaluate('Id');
  });
});

See Also