<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Parsing XML data from fields in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137418#M37665</link>
    <description>&lt;P&gt;I was running into the same problem where I only needed a simple table merging a couple of xml values from many, and potentially multiple times per event.&lt;/P&gt;

&lt;P&gt;To build off of what sideview ♦ explained, and from the &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.5/SearchReference/mvexpand"&gt;mvexpand&lt;/A&gt; docs,  I think I have a way to help you get just the fields you care about in a simple table.  Notice first few lines are same as what was already posted&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rename "result{@name}" as result_name
| fields result_name result
| eval zipped=mvzip(result_name,result)
| mvexpand zipped
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is where the code changes a little bit to meet what I think you are requesting.  You can actually just rex out of the new field you just created&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=zipped "(?&amp;lt;result_name&amp;gt;\S+),(?&amp;lt;result&amp;gt;\d+)"
| table result_name result
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Should be displayed like &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;result_name            result
MISCONF_STATUS.SUCCESS 154
MISCONF_RISK.HIGH      39
MISCONF_ALL            606
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;These results are then connected so you could get only specific events by appending&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| where result_name="MISCONF_ALL" AND result="606"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For some visualizations you can also change &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| table result_name result 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;to something like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats values(result_name) by result
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps&lt;/P&gt;</description>
    <pubDate>Wed, 19 Aug 2015 15:31:14 GMT</pubDate>
    <dc:creator>iamtags</dc:creator>
    <dc:date>2015-08-19T15:31:14Z</dc:date>
    <item>
      <title>Parsing XML data from fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137405#M37652</link>
      <description>&lt;P&gt;Hello, after researching a lot of information I still can not recorgnise how to solve this problem.&lt;BR /&gt;
I have an xml file added to splunk, and I've extracted fields through KV_MODE = xml.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;          &amp;lt;result name="MISCONF_STATUS.SUCCESS"&amp;gt;&amp;lt;![CDATA[154]]&amp;gt;&amp;lt;/result&amp;gt;
          &amp;lt;result name="MISCONF_RISK.HIGH"&amp;gt;&amp;lt;![CDATA[39]]&amp;gt;&amp;lt;/result&amp;gt;
          &amp;lt;result name="MISCONF_ALL"&amp;gt;&amp;lt;![CDATA[606]]&amp;gt;&amp;lt;/result&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So I have two fields here: result{@name} and result. the second is CDATA value. But the problem is they are not connected between eachother. &lt;BR /&gt;
how to define  that MISCONF_STATUS.SUCCESS = 154? And so on.&lt;BR /&gt;
I tried to make a chart using this two fields, but it is not working at all.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2015 14:21:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137405#M37652</guid>
      <dc:creator>Kabobgub</dc:creator>
      <dc:date>2015-04-07T14:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing XML data from fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137406#M37653</link>
      <description>&lt;P&gt;I would imagine you can use regex for this....  Should be able to generate a field based on a regular expression.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2015 14:23:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137406#M37653</guid>
      <dc:creator>markthompson</dc:creator>
      <dc:date>2015-04-07T14:23:07Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing XML data from fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137407#M37654</link>
      <description>&lt;P&gt;To clarify - the specific XML you posted ends up in a single event,  and that event has two fields, both of which have big "multivalue" values of (MISCONF_STATUS.SUCCESS,  MISCONF_RISK.HIGH, MISCONF_ALL),    and   154,29,606.  If you can confirm this then I think I can give you a search language answer. &lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:26:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137407#M37654</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2020-09-28T19:26:14Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing XML data from fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137408#M37655</link>
      <description>&lt;P&gt;Almost. Actually it is situated between &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;group &amp;gt; 
   &amp;lt;service&amp;gt;
        "this part"
   &amp;lt;/service&amp;gt;
&amp;lt;/group &amp;gt; 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The rest is right.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2015 15:39:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137408#M37655</guid>
      <dc:creator>Kabobgub</dc:creator>
      <dc:date>2015-04-07T15:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing XML data from fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137409#M37656</link>
      <description>&lt;P&gt;Try something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search with field _raw |  rex mode=sed "s/(\&amp;gt;\&amp;lt;\!\[CDATA\[)([^\]]+)(\]\])/ value=\2/g" | spath | rename result{@*} as * | eval {name}=value
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Apr 2015 15:42:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137409#M37656</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-04-07T15:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing XML data from fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137410#M37657</link>
      <description>&lt;P&gt;somesoni2's sed based approach may well be the best one,  but here's some fun search language that can do the same. &lt;/P&gt;

&lt;P&gt;I'm assuming that you have big multiline events that each have big multivalue values for your two fields "result{@name}" and "result"&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rename "result{@name}" as result_name
| eval zipped=mvzip(result_name,result)
| streamstats count as counter
| mvexpand zipped
| eval zipped = split(zipped,",")
| eval result = mvindex(zipped,0)
| eval {result}=mvindex(zipped,1)
| fields - zipped
| stats values(*) as * by counter
| fields - counter
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It's a bit of a circus act but it'll work.   eval's mvzip command can zip up two big multivalue values into a third multivalue field whose values look like "foo1,bar1"    "foo2,bar2"  etc.    Then we kinda of take the results apart and put them back together again the way we need them. &lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2015 15:55:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137410#M37657</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2015-04-07T15:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing XML data from fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137411#M37658</link>
      <description>&lt;P&gt;It seems to be right, but not working.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2015 16:04:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137411#M37658</guid>
      <dc:creator>Kabobgub</dc:creator>
      <dc:date>2015-04-07T16:04:57Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing XML data from fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137412#M37659</link>
      <description>&lt;P&gt;Thanks. It should work, but in this case I have a table with ALL my fields displayed. Could you tell me how can I use only this two fields?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2015 16:22:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137412#M37659</guid>
      <dc:creator>Kabobgub</dc:creator>
      <dc:date>2015-04-07T16:22:49Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing XML data from fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137413#M37660</link>
      <description>&lt;P&gt;It will work fine with other field values.  They should be carried along throughout. &lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2015 16:45:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137413#M37660</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2015-04-07T16:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing XML data from fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137414#M37661</link>
      <description>&lt;P&gt;The reason it is not suitable, that I have some junk fields in this case. All I need is to connect this two fields and have some visualisation of them. Thanks for your solution, but It differs a little from what I need. I will apreciate if you will give me some advice for my case&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2015 12:05:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137414#M37661</guid>
      <dc:creator>Kabobgub</dc:creator>
      <dc:date>2015-04-08T12:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing XML data from fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137415#M37662</link>
      <description>&lt;P&gt;I'm afraid that I do not understand the problem you are trying to describe. Possibly because it is not a problem at all.  can you describe why you think the other junk field values prevent this solution from giving you your visualization with this solution? &lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2015 15:29:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137415#M37662</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2015-04-08T15:29:34Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing XML data from fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137416#M37663</link>
      <description>&lt;P&gt;Problem is that this is part of very wide system and this search generated too much data for the current visualization. I will really appreciate if you will tell me, how can I customize this search or what commands I need to use for my goals. For example if I need to see values of MISCONF_RISK.HIGH only or values of MISCONF_ALL fields or values exept MISCONF_STATUS.SUCCESS. I've tried some ways to do it but is too complicated for me. &lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:29:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137416#M37663</guid>
      <dc:creator>Kabobgub</dc:creator>
      <dc:date>2020-09-28T19:29:51Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing XML data from fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137417#M37664</link>
      <description>&lt;P&gt;If you just want these two fields,  then you want to insert a fields command to explicitly filter out all other fields. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rename "result{@name}" as result_name
 | fields result_name result
 | eval zipped=mvzip(result_name,result)
 | streamstats count as counter
 | mvexpand zipped
 | eval zipped = split(zipped,",")
 | eval result = mvindex(zipped,0)
 | eval {result}=mvindex(zipped,1)
 | fields - zipped
 | stats values(*) as * by counter
 | fields - counter
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you're getting an error that the search generated too much data for the visualization, that has more to do with the visualization you're trying to use.   For instance if you try to generate a 1 year timechart with a 5 minute granularity you'll get errors like that in the UI. &lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2015 16:55:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137417#M37664</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2015-04-09T16:55:21Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing XML data from fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137418#M37665</link>
      <description>&lt;P&gt;I was running into the same problem where I only needed a simple table merging a couple of xml values from many, and potentially multiple times per event.&lt;/P&gt;

&lt;P&gt;To build off of what sideview ♦ explained, and from the &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.5/SearchReference/mvexpand"&gt;mvexpand&lt;/A&gt; docs,  I think I have a way to help you get just the fields you care about in a simple table.  Notice first few lines are same as what was already posted&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rename "result{@name}" as result_name
| fields result_name result
| eval zipped=mvzip(result_name,result)
| mvexpand zipped
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is where the code changes a little bit to meet what I think you are requesting.  You can actually just rex out of the new field you just created&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=zipped "(?&amp;lt;result_name&amp;gt;\S+),(?&amp;lt;result&amp;gt;\d+)"
| table result_name result
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Should be displayed like &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;result_name            result
MISCONF_STATUS.SUCCESS 154
MISCONF_RISK.HIGH      39
MISCONF_ALL            606
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;These results are then connected so you could get only specific events by appending&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| where result_name="MISCONF_ALL" AND result="606"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For some visualizations you can also change &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| table result_name result 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;to something like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats values(result_name) by result
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps&lt;/P&gt;</description>
      <pubDate>Wed, 19 Aug 2015 15:31:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parsing-XML-data-from-fields/m-p/137418#M37665</guid>
      <dc:creator>iamtags</dc:creator>
      <dc:date>2015-08-19T15:31:14Z</dc:date>
    </item>
  </channel>
</rss>

