Splunk Cloud

Search Reference

Download manual as PDF

Download topic as PDF



Extracts the xpath value from field and sets the outfield attribute.


xpath [outfield=<field>] <xpath-string> [field=<field>] [default=<string>]

Required arguments

Syntax: <string>
Description: Specifies the XPath reference.

Optional arguments

Syntax: field=<field>
Description: The field to find and extract the referenced xpath value from.
Default: _raw
Syntax: outfield=<field>
Description: The field to write, or output, the xpath value to.
Default: xpath
Syntax: default=<string>
Description: If the attribute referenced in xpath doesn't exist, this specifies what to write to the outfield. If this isn't defined, there is no default value.


The xpath command is a distributable streaming command. See Command types.


1. Extract values from a single element in _raw XML events

You want to extract values from a single element in _raw XML events and write those values to a specific field.

The _raw XML events look like this:

      <bar nickname="spock">
      <bar nickname="scotty">
      <bar nickname="bones">

Extract the nickname values from _raw XML events. Output those values to the name field.

sourcetype="xml" | xpath outfield=name "//bar/@name"

2. Extract multiple values from _raw XML events

Extract multiple values from _raw XML events

The _raw XML events look like this:

   <DataSet xmlns="">

   <DataSet xmlns="">

Extract the identity_id and instrument_id from the _raw XML events:

... | xpath outfield=identity_id "//DataSet/identity_id"

This search returns two results: identity_id=3017669 and identity_id=1037669.

To extract a combination of two elements, sname with a specific value and instrument_id, use this search:

... | xpath outfield=instrument_id "//DataSet[sname=\"BARC\"]/instrument_id"

Because you specify sname="BARC", this search returns one result: instrument_id=912383KM1.

See also

extract, kvform, multikv, rex, spath, xmlkv


Have questions? Visit Splunk Answers and see what questions and answers the Splunk community has using the xpath command.


This documentation applies to the following versions of Splunk Cloud: 6.6.3, 7.0.0, 7.0.3, 7.0.5, 7.0.2, 7.0.8, 7.1.3, 7.1.6, 7.2.3, 7.2.4, 7.2.6


Sorry -- my previous comment didn't appear correctly. The first example was XML with a "type" attribute. The second example was XML with a "xsi:type" attribute.

December 8, 2014

It appears that Splunk's xpath doesn't handle namespaces correctly? xpath can successfully extract the CallType from this:<br /><br />17<br /><br />But fails to extract anything if you try it on this:<br /><br />17

December 8, 2014

No problem Sophy, thanks for pointing me to spath - will take a look at it

July 25, 2012

Izakw, thanks! i corrected the examples. you may also want to check out the spath command for XML and JSON field extraction.

Sophy, Splunker
July 24, 2012

Tried on Splunk 4.3.3 , it didn't work as documented. We had to specify the outfield= before the XPath expression: <br /><br />This works: xpath outfield=identity_id "//DataSet/identity_id" <br />This doesn't work: xpath "//DataSet/identity_id" outfield=identity_id

July 24, 2012

Was this documentation topic helpful?

Enter your email address, and someone from the documentation team will respond to you:

Please provide your comments here. Ask a question or make a suggestion.

You must be logged into splunk.com in order to post comments. Log in now.

Please try to keep this discussion focused on the content covered in this documentation topic. If you have a more general question about Splunk functionality or are experiencing a difficulty with Splunk, consider posting a question to Splunkbase Answers.

0 out of 1000 Characters