Splunk Search

XML Field Extraction -- Multiple Lines

ksimpkins
New Member

I am new to Splunk and have been messing with this for about a week so I am looking to the community to help. I pretty much have multiple xml errors that I am trying to extract the error code "VOSCM0000I", the severity "Info" and the message "Transaction successful" out of multiple lines over a duration. Top offender over a period of time.

Any thoughts?

 <ResponseMessage>
    <mes:StatusCode>1</mes:StatusCode>
    <mes:BusinessMessage>
      <mes:Code>VOSCM0000I</mes:Code>
      <mes:Severity>Info</mes:Severity>
      <mes:LocalizedMessage>Transaction successful</mes:LocalizedMessage>
    </mes:BusinessMessage>
    <mes:BusinessMessage>
      <mes:Code>RENTAL003067</mes:Code>
      <mes:Severity>Error</mes:Severity>
      <mes:FieldName>ValidateTicketInput.ticket</mes:FieldName>
      <mes:LocalizedMessage>Total renter charge amount for this ticket obtained from pricing and payment is not matching.</mes:LocalizedMessage>
    </mes:BusinessMessage>
  </ResponseMessage>
Tags (1)
0 Karma
1 Solution

lguinn2
Legend

I like Martin's solution, but I would finish it differently. Either should work, though.

yoursearchhere
| spath output=msg path=ResponseMessage.mes:BusinessMessage 
| mvexpand msg
| rex "(?m)mes\:Code\>(?<Code>.*?)\<.*?mes\:Severity\>(?<Severity>.*?)\<.*?mes\:LocalizedMessage\>(?<Message>.*?)\<"
| top Code Severity Message

View solution in original post

lguinn2
Legend

I like Martin's solution, but I would finish it differently. Either should work, though.

yoursearchhere
| spath output=msg path=ResponseMessage.mes:BusinessMessage 
| mvexpand msg
| rex "(?m)mes\:Code\>(?<Code>.*?)\<.*?mes\:Severity\>(?<Severity>.*?)\<.*?mes\:LocalizedMessage\>(?<Message>.*?)\<"
| top Code Severity Message

lguinn2
Legend

Good point - I wasn't thinking about the fact that XML is order-independent for subelements.

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

An upside to the spath way is that it ignores different orderings and allows for optional elements without mucking up the regular expression - if for instance there were events with no localized message the expression would not match at all.

martin_mueller
SplunkTrust
SplunkTrust

For the extraction spath is your friend:

...  | spath output=msg path=ResponseMessage.mes:BusinessMessage | mvexpand msg | spath input=msg output=Code path=mes:Code | and so on
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!

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...

SPL2 Deep Dives, AppDynamics Integrations, SAML Made Simple and Much More on Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...