Version: 17.07
Supported Since: 17.07
A Get Attribute processor is a processing element which accepts a message with an XML payload, selects an attribute from that by evaluating a provided XPath expression, and then sets value of that attribute to a scope variable with the given name.
In order to use this processing element, you must first select the Regular XML Processors dependency from the processor list when you are creating an empty Ultra project. If you have already created a project, you can add this dependency via Component Registry. From Tools menu, select Ultra Studio → Component Registry and from the Processors list, select the Regular XML Processors dependency. |
Next |
The message will be sent to this outport if the attribute extraction is executed successfully |
On Exception |
The message will be sent to this outport if the processing element failed to extract the attribute due to some reason |
XPath * |
Basic |
The XPath expression to select the attribute to be extracted |
Variable Name * |
Basic |
The name of the scope variable to store the extracted attribute value |
Namespaces |
Basic |
If any custom namespaces are being used inside XPath expression, those should be defined as a map with those namespaces as keys and the corresponding namespace URIs as values. |
In the following use case, a food item distributor receives item order requests from the retailers through an SFTP server
as XML files. The top level element of each order (i.e. <order>
element) contains an attribute named vendor
, which
is the unique identifier of the vendor to whom this order is intended to.
<?xml version="1.0" encoding="UTF-8"?>
<order id="14566" vendor="347886">
<item>
<id>7685</id>
<amount>400</amount>
</item>
<item>
<id>2345</id>
<amount>100</amount>
</item>
</order>
The backend ordering system used by the distributor accepts orders through a JMS queue but it expects this vendor ID as a transport header in order to forward the order requests to the corresponding vendors.
Therefore the requirement is to get the order requests from the source SFTP server, extract the vendor ID from the attribute, add it as a transport header and dispatch the message to the ordering system’s JMS queue.
Prerequisites
In order to implement following use case following dependencies should be selected when an empty Ultra project is being created.
If the project is already created, above dependencies can be added via Component Registry. From Tools menu, select Ultra Studio → Component Registry and from the Connectors list and Processors list, select above dependencies. |
In this flow, an SFTP ingress connector is used to retrieve the order requests from the source SFTP server and its "Processor" outport is connected to the inport of the Get Attribute processor so that the XML message received by the connector is handed over to the processor next.
The XPath property of the processor is configured as /order/@vendor
and the Variable Name property is set as
vendor_id
, so that the processing element will extract the value of vendor attribute of the <order>
element and set
it as the value of the scope variable named vendor_id.
If any custom namespaces are being used inside XPath expression, those should be defined as a map in the Namespaces property, with those namespaces as keys and the corresponding namespace URIs as values. |
Then the "Next" outport of the Get Attribute processor is connected to the inport of an Add Transport Header processor and its properties are configured as below, so that it will read the value of the scope variable vendor_id and set it as an Integer transport header with name vendor.
Transport Header Name : vendor
Use Variable : true
Value : vendor_id
Header Variable Type : Integer
Propagate Variable Search : false
Finally the resulting message is dispatched to the destination JMS queue using a Spring JMS egress connector.