Sometimes it is convenient to process the full message from within a java UDF. This can be done using the StreamTransformation, but as an alternative, XPath expressions can be used as well...

 In order to run XPath expressions, several java libraries need to be defined at the imports section.

imports for UDF

To evaluate XPath expressions the developer has the choice of either returning the node-list or a single value as string. The relevant coding is shown below. 

...
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    // factory.setNamespaceAware(true);
    DocumentBuilder builder;
    Document doc = null;
...	
    try {
      builder = factory.newDocumentBuilder();
      
      // Create XPathFactory object
      XPathFactory xpathFactory = XPathFactory.newInstance();
      // Create XPath object
      XPath xpath = xpathFactory.newXPath();
      XPathExpression expr;
...
        try {
          doc = builder.parse( new InputSource(new StringReader(varXML))) ;
          expr = xpath.compile("/Your/XPath/Expression/text()");
          ... = (String) expr.evaluate(doc, XPathConstants.STRING);
          ....		  
        } 
        // catch ( XPathExpressionException | SAXException | IOException e) {
        catch ( Exception e) {
            return "xpath exception";
          // e.printStackTrace();
        }
      } // for  i
    } // end of try
    catch   (ParserConfigurationException e) {
      return "exception ParserConfiguration";
    }