Splunk Search

How do I extract xml tag using regex?

merrin
Engager

I tried to extract xml tagNames as fields fieldNameStartTag and fieldNameEndTag using the following.

rex field=_raw "<(?.)>([^<]+)</(?.)>"
But it does not extract all tags correctly. For example I have this xml:

abc
xyz

What I'm looking for is fieldNameStartTag and/or fieldNameEndTag to have values "ChildOne" and "ChildTwo". But the regex above gives me values like these:
1. Parent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.abcd.com"> abc
2. ChildOne>xyz

Any help is appreciated.

Tags (2)
0 Karma

gkanapathy
Splunk Employee
Splunk Employee

You should use the spath command, if you're on 4.3 or higher. If you're on older versions, the xmlkv command will also work for you.

emechler_splunk
Splunk Employee
Splunk Employee

Have you checked out the xmlkv command? This allows you to automatically extract KV pairs from XML formatted data without any regex's:

http://docs.splunk.com/Documentation/Splunk/4.3.1/SearchReference/xmlkv

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...