AnsweredAssumed Answered

XPath null object returned using groovy to select node

Question asked by ops-itoperations954452 on Oct 19, 2018
Latest reply on Oct 19, 2018 by britto.parthalomew

I have some basic code with which I am trying to select a data element from a document.

I cannot figure out what I'm doing wrong why it is only returning null values.

 

import org.jdom.input.SAXBuilder;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.xpath.XPath;
import org.jdom.output.XMLOutputter;
import com.boomi.execution.ExecutionUtil;
logger = ExecutionUtil.getBaseLogger();
InputStream is = dataContext.getStream(0);
Properties props = dataContext.getProperties(0);

// Build XML Document
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(is);
XMLOutputter xmOut = new XMLOutputter();

logger.warning("DOC + " + xmOut.outputString(doc));

XPath xMatrixManager = XPath.newInstance("//person");
XPath xManagerID = XPath.newInstance("//manager_id");



// Select a single node and grab the actual value
matrixManagerElement = xMatrixManager.selectSingleNode(doc);
managerIDElement = xManagerID.selectSingleNode(doc);

 

 

 

Both elements are returning null.

 

The XML (with PII removed) returned when I output doc is:

 

<?xml version="1.0" encoding="UTF-8"?>
<CompoundEmployee>
<id>999</id>
<person xmlns="urn:sfobject.sfapi.successfactors.com">
<employment_information>
<job_information>
<manager_id>1005</manager_id>
</job_information>
<compensation_information>
</compensation_information>
</employment_information>
</person>
</CompoundEmployee>

Outcomes