<operate>
¶
The <operate>
element provides powerful batch operations on templates for data transformation. It supports both XML (using XPath) and JSON (using JSONPath) templates with extensive operation capabilities.
Overview¶
The operate element reads operation definitions from a CSV file and applies them to templates, enabling: - Batch data transformations - Template modifications before data generation - Dynamic value injection using generators - Complex structural operations - Function execution
Attributes¶
Attribute | Required | Description | Default |
---|---|---|---|
source |
Yes | CSV file path containing operations and models | - |
operation_prefix |
No | Prefix for operation column names in CSV | op |
template_not_found_action |
No | Action when template is missing: warn , error , ignore |
warn |
operation_not_matched_action |
No | Action when operation is invalid: warn , error , ignore |
warn |
template-dir |
No | Base directory for template files | - |
CSV File Format¶
The CSV file must contain:
- id
: Unique identifier for each artifact
- template
: Path to the template file (relative to template-dir if specified)
- Operation columns: Named with the operation_prefix (e.g., op1
, op2
, op3
)
Operation Types¶
Basic Operations¶
set¶
Updates or creates a value at the specified path.
XML Example:
1 2 |
|
JSON Example:
1 2 |
|
delete¶
Removes a node/property at the specified path.
XML Example:
1 2 |
|
JSON Example:
1 2 |
|
Advanced Structural Operations¶
XML-Specific Operations¶
-
replaceChildren: Replace all children of a node
1 2
op1 replaceChildren(//root/data,<item>New Item</item>)
-
appendChild: Add a child to a node
1 2
op1 appendChild(//root/metadata,<updated>2025-07-17</updated>)
-
upsertNode: Update or insert a node
1 2
op1 upsertNode(//root/status,active)
-
mergeAttributes: Merge attributes into a node
1 2
op1 mergeAttributes(//root,id="test-123" enhanced="true")
-
clearChildren: Remove all children from a node
1 2
op1 clearChildren(//root/temp)
-
upsertAttribute: Update or insert an attribute
1 2
op1 upsertAttribute(//root,version="2.0")
JSON-Specific Operations¶
-
mergeObject: Merge objects
1 2
op1 mergeObject($.config,{"timeout": 30, "ssl": true})
-
upsertProperty: Update or insert a property
1 2
op1 upsertProperty($.metadata.version,2.0)
-
replaceArray: Replace an entire array
1 2
op1 replaceArray($.items,[{"id": 3, "name": "New Item"}])
-
appendItem: Add item to array
1 2
op1 appendItem($.tags,new_tag)
-
clearArray: Empty an array
1 2
op1 clearArray($.temp)
Function Operations¶
Execute functions without modifying content:
1 2 |
|
Dynamic Value Injection¶
Use generators and variables within operations:
1 2 |
|
Complex Examples¶
Example 1: Basic XML Operations¶
Setup (datamimic.xml):
1 2 3 |
|
CSV (operations.opctl.csv):
1 2 3 |
|
Example 2: JSON with Complex Paths¶
1 2 3 |
|
Example 3: Healthcare Business Domain¶
Setup:
1 2 3 4 5 6 7 8 9 |
|
CSV:
1 2 |
|
Example 4: Error Handling¶
1 2 3 4 5 6 |
|
Best Practices¶
- Operation Order: Plan operations carefully as they are applied sequentially
- Avoid modifying nodes after deletion
-
Create parent nodes before children
-
Path Validation: Ensure paths exist before operations
- Use upsert operations for uncertain paths
-
Handle missing paths gracefully with error actions
-
Performance: For large datasets
- Group related operations together
- Use batch operations when possible
-
Consider template complexity
-
Error Handling:
- Set appropriate
template_not_found_action
based on requirements - Use
warn
for development,error
for production -
Monitor logs for operation warnings
-
Maintainability:
- Use descriptive IDs in CSV files
- Document complex operations
- Keep templates organized in logical directories
Logical Validation¶
The operate system detects and reports invalid operation sequences: - Operations on deleted nodes - Conflicting modifications - Invalid paths after structural changes
Integration with Generators¶
Operate seamlessly integrates with DATAMIMIC generators: - Use generator expressions in set operations - Combine with variables for dynamic content - Support for all DATAMIMIC generator types
Examples by Use Case¶
E-commerce Product Catalog¶
1 2 |
|
Financial Services¶
1 2 |
|
Government Permits¶
1 2 |
|