Using name/local-name functions with XPath node

I have the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<item>
    <recType>dateAggregatedValues</recType>
    <periodStartDate>2021-01-01</periodStartDate>
    <values>
        <Finland>1</Finland>
        <Taiwan>2</Taiwan>
        <Russia>2</Russia>
    </values>
</item>

I need to create a row for each //values/* element, with the node name (country name) and node value as columns. To get the node name, using XPath name() or local-name() functions are required, and my understanding is that the XPath node supports v1.0 functions and syntax. But when I try to get the node names using “name(//values/*)” or any other alternative as the XPath (KNIME v4.2.2), on execution I get the error:

ERROR : KNIME-Worker-100-XPath 0:1002 : : Node : XPath : 0:1002 : Execute failed: javax.xml.xpath.XPathExpressionException: org.apache.xpath.XPathException: Can not convert #STRING to a NodeList!
java.lang.IllegalStateException: javax.xml.xpath.XPathExpressionException: org.apache.xpath.XPathException: Can not convert #STRING to a NodeList!
at org.knime.xml.node.xpath2.CellFactories.XPathCollectionCellFactory.getCell(XPathCollectionCellFactory.java:209)
at org.knime.xml.node.xpath2.CellFactories.XPathCollectionCellFactory.getCells(XPathCollectionCellFactory.java:183)
at org.knime.core.data.container.RearrangeColumnsTable.calcNewCellsForRow(RearrangeColumnsTable.java:553)
at org.knime.core.data.container.ColumnRearrangerFunction.compute(ColumnRearrangerFunction.java:121)
at org.knime.xml.node.xpath2.XPathNodeModel.executeQueriesAndUngroupToRowsOnTheFly(XPathNodeModel.java:252)
at org.knime.xml.node.xpath2.XPathNodeModel.executeInternal(XPathNodeModel.java:208)
at org.knime.xml.node.xpath2.XPathNodeModel.execute(XPathNodeModel.java:188)
at org.knime.core.node.NodeModel.execute(NodeModel.java:747)
at org.knime.core.node.NodeModel.executeModel(NodeModel.java:576)
at org.knime.core.node.Node.invokeFullyNodeModelExecute(Node.java:1236)
at org.knime.core.node.Node.execute(Node.java:1016)
at org.knime.core.node.workflow.NativeNodeContainer.performExecuteNode(NativeNodeContainer.java:558)
at org.knime.core.node.exec.LocalNodeExecutionJob.mainExecute(LocalNodeExecutionJob.java:95)
at org.knime.core.node.workflow.NodeExecutionJob.internalRun(NodeExecutionJob.java:201)
at org.knime.core.node.workflow.NodeExecutionJob.run(NodeExecutionJob.java:117)
at org.knime.core.util.ThreadUtils$RunnableWithContextImpl.runWithContext(ThreadUtils.java:334)
at org.knime.core.util.ThreadUtils$RunnableWithContext.run(ThreadUtils.java:210)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.knime.core.util.ThreadPool$MyFuture.run(ThreadPool.java:123)
at org.knime.core.util.ThreadPool$Worker.run(ThreadPool.java:246)
Caused by: javax.xml.xpath.XPathExpressionException: org.apache.xpath.XPathException: Can not convert #STRING to a NodeList!
at org.apache.xpath.jaxp.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:197)
at org.knime.xml.node.xpath2.CellFactories.XPathCollectionCellFactory.evaluateStringSet(XPathCollectionCellFactory.java:380)
at org.knime.xml.node.xpath2.CellFactories.XPathCollectionCellFactory.getCell(XPathCollectionCellFactory.java:203)
… 20 more
Caused by: org.apache.xpath.XPathException: Can not convert #STRING to a NodeList!
at org.apache.xpath.objects.XObject.error(XObject.java:709)
at org.apache.xpath.objects.XObject.nodelist(XObject.java:455)
at org.apache.xpath.jaxp.XPathExpressionImpl.getResultAsType(XPathExpressionImpl.java:357)
at org.apache.xpath.jaxp.XPathExpressionImpl.eval(XPathExpressionImpl.java:100)
at org.apache.xpath.jaxp.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:184)
… 22 more

Is my syntax wrong? If not, how do I pass a nodeset to the name() function? Thanks!

Hi @bfrutchey , as per the error message “Can not convert #STRING to a NodeList!”, it sounds like you are trying to retrieve a string as a NodeList.

Can you please share your syntax or your workflow or show the configuration screen of the XPath node?

Here is a screenshot of one attempt.

Hi @bfrutchey , thank you for the screenshot.

As you can see, you are retrieving a string, but you are trying to retrieve it as a Collection Cell, exactly what the error message said.

You need to select the “Single Cell” option:

1 Like