Products | Versions |
---|---|
TIBCO ActiveMatrix BusinessWorks Plug-in Development Kit | 6.x |
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