<?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 Extracting value from XML tags in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Extracting-value-from-XML-tags/m-p/183103#M36673</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Can you help me out in extracting information between the XML tags and perform division operation on it.&lt;/P&gt;

&lt;P&gt;In my XML file I have something called &lt;FILESIZE&gt; 24 &lt;/FILESIZE&gt;, this is one event and other event is &lt;TRANSTIME&gt; 6 &lt;/TRANSTIME&gt;&lt;/P&gt;

&lt;P&gt;Now I need to extract the filesize value i.e. 24 and transtime value i.e. 6 and want to perform divison of filesize/transtime and splunk needs to show the output value i.e. 24/6=4.&lt;/P&gt;

&lt;P&gt;I tried out using xmlkv and spath, it is not working out.&lt;/P&gt;

&lt;P&gt;Can you help!&lt;/P&gt;

&lt;P&gt;Cheers,&lt;BR /&gt;
Sushma.&lt;/P&gt;</description>
    <pubDate>Wed, 12 Mar 2014 04:51:52 GMT</pubDate>
    <dc:creator>sushma6</dc:creator>
    <dc:date>2014-03-12T04:51:52Z</dc:date>
    <item>
      <title>Extracting value from XML tags</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Extracting-value-from-XML-tags/m-p/183103#M36673</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Can you help me out in extracting information between the XML tags and perform division operation on it.&lt;/P&gt;

&lt;P&gt;In my XML file I have something called &lt;FILESIZE&gt; 24 &lt;/FILESIZE&gt;, this is one event and other event is &lt;TRANSTIME&gt; 6 &lt;/TRANSTIME&gt;&lt;/P&gt;

&lt;P&gt;Now I need to extract the filesize value i.e. 24 and transtime value i.e. 6 and want to perform divison of filesize/transtime and splunk needs to show the output value i.e. 24/6=4.&lt;/P&gt;

&lt;P&gt;I tried out using xmlkv and spath, it is not working out.&lt;/P&gt;

&lt;P&gt;Can you help!&lt;/P&gt;

&lt;P&gt;Cheers,&lt;BR /&gt;
Sushma.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Mar 2014 04:51:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Extracting-value-from-XML-tags/m-p/183103#M36673</guid>
      <dc:creator>sushma6</dc:creator>
      <dc:date>2014-03-12T04:51:52Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting value from XML tags</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Extracting-value-from-XML-tags/m-p/183104#M36674</link>
      <description>&lt;P&gt;Hi sushma6,&lt;/P&gt;

&lt;P&gt;something like this should work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | spath | eval myDevision=filesize/transtime | table myDevision
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is because when &lt;CODE&gt;spath&lt;/CODE&gt; is called with no path argument, &lt;CODE&gt;spath&lt;/CODE&gt; runs in "auto-extract" mode, where it finds and extracts all the fields from the first 5000 characters in the input field which defaults to _raw if another input source isn't specified.&lt;/P&gt;

&lt;P&gt;If &lt;CODE&gt;spath&lt;/CODE&gt;really does not work, you could try some regex to get the fields like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex "\&amp;lt;filesize\&amp;gt;\s(?&amp;lt;myFilesize&amp;gt;\d+)\s.+\&amp;lt;transtime\&amp;gt;\s(?&amp;lt;myTranstime&amp;gt;\d+)\s" | eval myDevision=myFilesize/myTranstime | table myDevision
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;btw, are you aware that there are some spaces around the numeric values or is this just a copy/paste error?&lt;BR /&gt;
In your case you can remove spaces from values like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | spath | eval myFilesize=ltrim(filesize) | eval myTranstime=ltrim(transtime) | eval myDevision=myFilesize/myTranstime | table myDevision
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;hope this helps ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Wed, 12 Mar 2014 06:26:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Extracting-value-from-XML-tags/m-p/183104#M36674</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-03-12T06:26:32Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting value from XML tags</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Extracting-value-from-XML-tags/m-p/183105#M36675</link>
      <description>&lt;P&gt;One possibility is to use an inline rex or EXTRACT via props.conf.  The inline rex(s) would look something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your base search&amp;gt; | rex "\&amp;lt;filesize\&amp;gt;\s*(?&amp;lt;fsize&amp;gt;\d+)\s*\&amp;lt;\/filesize\&amp;gt;" | rex "\&amp;lt;transtime\&amp;gt;\s*(?&amp;lt;ttime&amp;gt;\d+)\s*\&amp;lt;\/transtime\&amp;gt;" | eval avgtime=fsize/ttime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Out of curiosity, what sort of trouble are you having with xmlkv and spath?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Mar 2014 06:28:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Extracting-value-from-XML-tags/m-p/183105#M36675</guid>
      <dc:creator>sbrant_splunk</dc:creator>
      <dc:date>2014-03-12T06:28:33Z</dc:date>
    </item>
  </channel>
</rss>

