Source:
public void transform(StructuredRecord input, Emitter<StructuredRecord> emitter) throws IOException { String xmlStr = input.get(config.field); if (xmlStr == null) { return; } try (Reader reader = new StringReader((String) input.get(config.field))) { InputSource source = new InputSource(reader); source.setEncoding(config.encoding); Document document; try { DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder(); document = documentBuilder.parse(source); } catch (ParserConfigurationException e) { throw new RuntimeException("Unable to create document builder.", e); } catch (SAXException e) { LOG.error("Unable to parse the xml document. This record will be dropped.", e); emitter.emitError(new InvalidEntry<>(31, e.getStackTrace()[0].toString() + " : " + e.getMessage(), input)); return; } NodeList nodeList; try { nodeList = (NodeList) xPathExpression.evaluate(document, XPathConstants.NODESET); } catch (XPathExpressionException e) { LOG.error("Unable to evaluate xpath for the xml document. This record will be dropped.", e); emitter.emitError(new InvalidEntry<>(31, e.getStackTrace()[0].toString() + " : " + e.getMessage(), input)); return; } for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); NodeList children = node.getChildNodes(); try { StructuredRecord.Builder builder = StructuredRecord.builder(schema); for (int j = 0; j < children.getLength(); j++) { Node childNode = children.item(j); String nodeName = childNode.getNodeName(); if (fieldNames.contains(nodeName)) { builder.convertAndSet(nodeName, childNode.getTextContent()); } } emitter.emit(builder.build()); } catch (Exception e) { LOG.error("Unable to create a record from the xpath element. This record will be dropped.", e); emitter.emitError(new InvalidEntry<>(31, e.getStackTrace()[0].toString() + " : " + e.getMessage(), input)); } } } }

Target:
public void transform(StructuredRecord input, Emitter<StructuredRecord> emitter) throws IOException { String xmlStr = input.get(config.field); if (xmlStr == null) { return; } try (Reader reader = new StringReader((String) input.get(config.field))) { InputSource source = new InputSource(reader); source.setEncoding(config.encoding); Document document; try { DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder(); document = documentBuilder.parse(source); } catch (ParserConfigurationException e) { throw new RuntimeException("Unable to create document builder.", e); } catch (SAXException e) { LOG.error("Unable to parse the xml document. This record will be dropped.", e); emitter.emitError(new InvalidEntry<>(31, "Unable to parse the xml document. This record will be dropped.", input)); return; } NodeList nodeList; try { nodeList = (NodeList) xPathExpression.evaluate(document, XPathConstants.NODESET); } catch (XPathExpressionException e) { LOG.error("Unable to evaluate xpath for the xml document. This record will be dropped.", e); emitter.emitError(new InvalidEntry<>(31, "Unable to evaluate xpath for the xml document. This record will be " + "dropped.", input)); return; } for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); NodeList children = node.getChildNodes(); try { StructuredRecord.Builder builder = StructuredRecord.builder(schema); for (int j = 0; j < children.getLength(); j++) { Node childNode = children.item(j); String nodeName = childNode.getNodeName(); if (fieldNames.contains(nodeName)) { builder.convertAndSet(nodeName, childNode.getTextContent()); } } emitter.emit(builder.build()); } catch (Exception e) { LOG.error("Unable to create a record from the xpath element. This record will be dropped.", e); emitter.emitError(new InvalidEntry<>(31, "Unable to create a record from the xpath element. This record " + "will be dropped.", input)); } } } }