Splunk Search

Join multiple fields from xml

roblr052
New Member

I want to join these different product_id's from an XML file into one table:

<product_detail> 
  <product_id>1003C</product_id>
<product_detail>
  <product_id>1002C</product_id>
</product_detail>

Example: 1003C,1002C

I've tried split, mvjoin, spath, and nothing works. Here's sample of my query:
source=xxxxxx.log
| xmlkv
| spath input=product_id
| table product_id
| eval product_id=split(product_id,";")
| eval product_id=mvjoin(product_id,";")

How do I get the output of these multiple values into a semi-colon?

Tags (4)
0 Karma

niketn
Legend

@roblr052, your sample XML data seems incorrect. Your first <product_detail> does not have an end node. I am not sure if that is how the data is or whether it was a type while posting the sample data here.

Following is a run anywhere example with corrected sample data and spath command:

|  makeresults
|  eval _raw="<data>
                 <product_detail> 
                    <product_id>1003C</product_id>
                 </product_detail>
                 <product_detail>
                    <product_id>1002C</product_id>
                 </product_detail>
              </data>"
| spath

Please try out and confirm.

If correct xml data is indexed, then either KV_MODE=xml should be used to get xml fields extracted automatically during search time field discovery.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Observability Simplified: Combining User Experience, Application Performance & ...

Tech Talk Observability Simplified: Combining User Experience, Application Performance & Network ...

Event Series May & June: From Network Visibility to Service Intelligence

Unifying the Network: Moving from Alert Noise to Service Intelligence with Splunk ITSI In today’s hybrid ...

Global Splunk User Group Events: May + June 2026

Your Splunk Community Awaits: Discover Upcoming User Group Events Worldwide    Staying ahead in the fast-paced ...