Products | Versions |
---|---|
TIBCO ActiveMatrix BusinessWorks Plug-in Development Kit | 6.x |
The BusinessWorks Plug-in development kit provides the method "public String getInputParameterStringValueByName()" which can be used to get the value of a string parameter according to the parameter name from the input. However, this method works in case the input has a flat XSD but in case the input is based on a hierarchical XSD that contains a complex type this method won't work.
In order to get the value of a string parameter for a complex type input element one can use the XMLUtil package to retrieve the complete input XML string and then parse the input XML obtained to fetch the value for the complex type element at the runtime.
The following sample code can be used to retrieve '//complexType/ComplexElementName' in the function evalOutput in the <activity name>SynchronousActivity.java or <activity name>AsynchronousActivity.java
Step 1) Add the following imports to <activity name>SynchronousActivity.java or <activity name>AsynchronousActivity.java
// begin-custom-code
// add your own business code here
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
// end-custom-code
Step 2) Add the following code to the evalOutput() method.
// begin-custom-code
// add your own business code here
String serializedNode = XMLUtils.serializeNode(inputData, this.activityContext.getXMLProcessingContext());
System.out.println(serializedNode);
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = builderFactory.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(serializedNode));
Document xmlDocument = builder.parse(is);
XPath xPath = XPathFactory.newInstance().newXPath();
String expression = "//complexType/ComplexElementName";
System.out.println("//complexType/ComplexElementName="+xPath.compile(expression).evaluate(xmlDocument, XPathConstants.STRING));
// end-custom-code