XML and JSON variable support
WSO2 Business Process Server 3.6.0 onwards supports XML and JSON variables which can be read,created or updated within a BPMN process as follows:
For more information on creating a BPMN process, see Creating a BPMN Process.Â
Access From | Read/Query | Create/Update |
---|---|---|
Java Service Task | Yes | Yes |
Condition Expressions | Yes | No |
Script Task | Yes | Yes |
BPMN REST API | Yes | Yes |
JSON
JSON Node Object
In WSO2 BPS, JSON variables are represented by JsonNodeObject
objects. The org.wso2.carbon.bpmn.core.types.datatypes.json.api.JsonNodeObject
wraps the com.fasterxml.jackson.databind.JsonNode
object and provides functions to query and update data in JSON format.
Function | Description |
---|---|
Object jsonPath(String jsonPathStr) | This function evaluates jsonPath over JsonNodeObject and returns the evaluation result. The returned object can be one of the following:
Note: This function returns a new object representing the evaluation results and not a reference to a node. Sample Return var fname = jsonJSVar.jsonPath("$.firstName"); var exec = jsonJSVar.jsonPath("$.execInfo");Â |
JsonNode unwrap() | This function unwraps and returns the wrapped JsonNode. |
A set of useful and frequently used functions that are available in JsonNode, are exposed from the JsonNodeObject to make it easier to use JSON variables. However, if other functionality that is available is required, those functions can be unwrapped and used using the org.wso2.carbon.bpmn.core.types.datatypes.json.api.JsonNodeObject.unwrap()
function. These functions are:Â
JsonNode findValue(String fieldName)
JsonNode findPath(String fieldName)
JsonNode findParent(String fieldName)
List<JsonNode> findValues(String fieldName, List<JsonNode> foundSoFar)
List<String> findValuesAsText(String fieldName, List<String> foundSoFar)
List<JsonNode> findParents(String fieldName, List<JsonNode> foundSoFar)
JsonNode path(String fieldName)
JsonNode path(int index)
String toString()
boolean equals(Object obj)
JsonNode get(int index)
JsonNode get(String fieldName)
boolean has(String fieldName)
boolean has(int index)
int size()
Iterator<JsonNode> elements()
Iterator<String> fieldNames()
Iterator<Map.Entry<String, JsonNode>> fields()
XML
With XML support, users can create variables with the XML data type and extract or set XML content with the help of the simple JAVA API provided in WSO2 BPS.Â
XML Document
XML variables are represented by the XMLDocument object org.wso2.carbon.bpmn.core.types.datatypes.xml.api.XMLDocument
which implements org.w3x.dom.Document
. It also provides a set of user friendly function to query and update XML content with XPath. The following functions are available for the XML variable type with WSO2 BPS.Â
Â
| |
---|---|
Description | This function evaluates the XPath query and returns the relevant element. |
xpathStr | The XPath expression that is to be evaluated. |
Return |
|
Â
| |
---|---|
Description | This function evaluates the XPath query and returns the specified return type. |
xpathStr | The XPath expression that is to be evaluated. |
returnType | The desired return type of the XPath evaluation. The supported return types are:
|
Return | The result of the XPath evaluation in the form of the specified return type. |
Â
| |
---|---|
Description | This function sets, replaces or updates an object (string/element) to match the XPath provided. If a new element is added, this API will clone it and merge the new node to the target location that the XPath points to and will return the new cloned node. |
xpathStr | The XPath to the target location where the object is to be set. |
obj | The string or node object to be set. |
Return | The node gets updated if the object is string and returns a newly added node if the object is an element. |
Â
| |
---|---|
Description | This function appends a child element to the target element. |
xpathToParent | The XPath to the parent node. |
element | The element that is to be appended. |
Return | The node either gets appended or returns a newly added node if the object is an element. |
Â
| |
---|---|
Description | This function inserts a new child node before the specified existing node. |
xpathToTargetNode | The XPath to the target node. |
element | The element that is to be inserted. |
Return | The node gets inserted. |
Â
| |
---|---|
Description | This function will serialize the XML object to a string. |
Â
| |
---|---|
Description | This function creates a new element. This is a util method. |