||
Skip to end of metadata
Go to start of metadata

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 FromRead/QueryCreate/Update
Java Service Task

Yes

Yes
Condition ExpressionsYesNo
Script TaskYesYes
BPMN REST APIYesYes

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.

FunctionDescription
Object jsonPath(String jsonPathStr)This function evaluates jsonPath over JsonNodeObject and returns the evaluation result.

The returned object can be one of the following:

  • If the result is a JSON object, it will return a com.fasterxml.jackson.databind.JsonNode.
  • If the result is a JSON array, it will return a com.fasterxml.jackson.databind.node.ArrayNode.
  • Main primitive data types (String, Integer, Byte, Character, Short, Long, Float, Double, Boolean)

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. 

 

Object xPath(String xpathStr)
DescriptionThis function evaluates the XPath query and returns the relevant element.
xpathStrThe XPath expression that is to be evaluated.
Return
  • A org.w3c.dom.NodeList is returned if there is more than one elements in the result.
  • A org.w3c.dom.Node object is returned if there is only one element in the result.

 

Object xPath(String xpathStr, String returnType)
DescriptionThis function evaluates the XPath query and returns the specified return type.
xpathStrThe XPath expression that is to be evaluated.
returnType

The desired return type of the XPath evaluation. The supported return types are:

    • NODESET
    • NODE
    • STRING
    • NUMBER
    • BOOLEAN
Return

The result of the XPath evaluation in the form of the specified return type.

 

Node set(String xPathStr, Object obj)
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.

xpathStrThe XPath to the target location where the object is to be set.
objThe 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.

 

Node appendChild(String xPathToParent, Element element)
Description

This function appends a child element to the target element.

xpathToParentThe XPath to the parent node.
elementThe element that is to be appended.
Return

The node either gets appended or returns a newly added node if the object is an element.

 

Node insertBefore(String xPathToTargetNode, Element element)
Description

This function inserts a new child node before the specified existing node.

xpathToTargetNodeThe XPath to the target node.
elementThe element that is to be inserted.
Return

The node gets inserted.

 

String toString()
Description

This function will serialize the XML object to a string.

 

Element createNewElement(String elementStr)
Description

This function creates a new element.

This is a util method.

  • No labels