In KNIME 4.4 the JSON to XML anytime a number shows up as a character in the first position in a field for conversion the value is modified by removing the leading numbers in the string and creates an error in the XML Path node.
ERROR XPath 0:1998:0:1565 Error while parsing XML in XML Cell
ERROR XPath 0:1998:0:1565 Execute failed: javax.xml.xpath.XPathExpressionException: javax.xml.transform.TransformerException: The context can not be null when the operation is context-dependent.
How does this get resolved?
Hi @Swimjunkie and welcome to the community!
Indeed, leading numbers are not allowed in an xml keys - that’s why they are removed (the original key is stored as attribute). There seems to be a bug related to the XML Path node (which I just reported to our developers), as it struggles to build the XML Tree hierarchy:
Meanwhile, could you try to transform your JSON such that the leading numbers are gone? You can use the “JSON to table” node for example, do the transformation (rename the columns or the like, depends on your data) and put it back to a JSON with the “Table to JSON” node.
Hope that helps! And thanks for reporting, best
Changing the values of the fields to modify values is beyond the control of the flow, so the round trip is not going to work.
You don’t need to modify the values prior to the workflow. Once you have your JSON within the workflow, you can change the names there, just before the “JSON to XML” node, e.g. with these four nodes:
This is the example workflow:
Does that work for you?
How do I modify the JSON regex statement to put and “x” in front of:
So we see:
All the best,
if its always “data.somenumber” you can use
(data\.)(\d) in the searchstring and
$1x$2 as the replacement in the “Column Rename (Regex)” node.
Instead I recommend replacing all the leading numbers, however, and search for
(^|\.)(\d) to be replaced with
$1x$2 so that the “XPath” will work properly:
As an explanation: two groups are generated by two pairs of brackets. The first one
(^|\.) matches the beginning of the column header or any dot in there (
^ to match the beginning,
| for ‘or’, and
\. for the dot, brackets to make it a group) in the column header. This group is accessed by the
$1 in the replacement. The second group
(\d) matches any following digit and is accessed by the
$2 in the replacement. Thus with
$1x$2 you will replace the whole match with both subgroups and an “x” in between (e.g. “1documents.17.annotations.shared.data.240_t” → “x1documents.x17.annotations.shared.data.x240_t”). I also highly recommend websites like https://regex101.com/ where you can build and test regex expressions easily, even with some explanation.
dropping info that this issue was addressed with KNIME version 4.4.1.
Find entire changelog here: KNIME Analytics Platform 4.4 | KNIME
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.