Xpath anomaly with attribute name with colon

I want to parse XML and get data from it in table format. I am using xpath node for this purpose.
XML has fixed set of nodes however the attribute of parent node may vary. E.g. some nodes may not have few attributes. See screenshot below. First variable node has two attributes less than second one.
image

In this case what I am expecting is for xpath to return missing cell for first one and value for second node in second row. Please see the way I have configured xpath. As attribute name has colon in it, I had to use name function.

The problem is xpath instead of returning blank cell in missing attribute column in first row it traverses further nodes till it finds attribute and gets that value. Hence output table has mixed values in a row.

Please suggest how can I fix it.

One another note, please suggest if there is any way to concatenate two xpath values in same column in knime xpath node.

Hi @ddnyaneshwar,
this happens because each xpath expression acts independenty of the others, so an expression just filters the nodes which satisfy the specified condition, ignoring what the other existing xpath conditions are extracting.

In your case, a solution could be to use 2 XPath nodes, one connected after the other: the first one extracts the “variable” node (using “Node(Multiple rows)” for type), and the other one, for each “variable” node returned by previous node, extracts its attribute values (using “String(SingleCell)” for type).

1 Like

Thank you Arofab. that helped!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.