XML Xpath multiple elements same name

Hi,

I’m reading an xml file with this structure via the xml reader to xpath:

image

The name value I can parse find in to a single column but the category values are a bit more tricky. My desired output is to have three columns named Category1, Category2 and Category3:

image

How do I configure Path to give me this desired output?

Thanks in advance

Providing us with a sample file that at best fully represents your problem could help finding a solution.

One guess is you will have to target “categories” in the xpath definition and user something like multi row and later transposer that our some sort of collection and split them later.

2 Likes

Thanks for the tip @mlauber71. Targeting categories using multi row gave me a string like “menmintsport”. Is there a good way of inserting a delimiter in the xpath query (like “men-mint-sport”) that I can then use to break the values apart in to three different columns?

Hi @cason,

you could use this workflow
Bildschirmfoto von 2020-09-22 21-18-37

XPath config
Bildschirmfoto von 2020-09-22 21-22-35

XML To JSON config … The Text body translated ... can be set with any string
Bildschirmfoto von 2020-09-22 21-19-12

JSON to Table config
Bildschirmfoto von 2020-09-22 21-19-23

Column Rename (Regex) config
Bildschirmfoto von 2020-09-22 21-30-05

OK. The solution does not match your requirements 100% :sweat_smile:
Bildschirmfoto von 2020-09-22 21-18-25

Best Regards
Andrew

2 Likes

Hi @cason and welcome back to the KNIME forum,

You can use index values to specify the categories like this:
/products/product/categories/category[1]

And name the column regarding the category index.

Here is an example:
27522-1-1.knwf (14.8 KB)

:blush:

6 Likes

Thank you @Andrew_Steel and @armingrudd, both solutions look great. In the end I chose @armingrudd solution since it ment less rework of my workflow. With this all three categories are parsed correctly.

Thanks again!

4 Likes

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