Splunk Search

Extract multiple field values from XML in Splunk

shangshin
Builder

Hi,
Please advise the splunk search to extract multiple field values from the xml in splunk.
For example, how can I get both the user name and user id using the sample xml below.

<users>
  <user>
    <user_name>John Jobs</user_name>
   <user_id>JJobs</user_id>
   <user_iemail>JJobs@example.com</user_email>
</user>
 <user>
    <user_name>Mary Ann</user_name>
   <user_id>mann</user_id>
   <user_iemail>mann@outlook.com</user_email>
 </user>
</users>
Tags (1)
0 Karma

sdaniels
Splunk Employee
Splunk Employee

You can use the spath command to get the values that you want. See the xml examples towards the bottom.

http://docs.splunk.com/Documentation/Splunk/5.0/SearchReference/Spath

You can also have Splunk extract all fields automatically for you:

http://splunk-base.splunk.com/answers/2889/automatically-extract-xml-key-value-pairs

0 Karma

sdaniels
Splunk Employee
Splunk Employee

Maybe you can update the XML to show what you are talking about. Right now it's hard to tell why it's not working for you.

0 Karma

shangshin
Builder

Thank you! This is very helpful.

I am able to extract most of the elements except for the element value with forward slash.

E.g.
the xml element below users.usr.url returns an empty value.
/en-GB/app/search/flashtimeline?q=search sourcetype

Is there a special function for this?

0 Karma
Get Updates on the Splunk Community!

A Prelude to .conf25: Your Guide to Splunk University

Heading to Boston this September for .conf25? Get a jumpstart by arriving a few days early for Splunk ...

4 Ways the Splunk Community Helps You Prepare for .conf25

.conf25 is right around the corner, and whether you’re a first-time attendee or a seasoned Splunker, the ...

Enhance Your Splunk App Development: New Tools & Support

UCC FrameworkAdd-on Builder has been around for quite some time. It helps build Splunk apps faster, but it ...