<?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 rex expression to extract field from XML message in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-to-extract-field-from-XML-message/m-p/364333#M107523</link>
    <description>&lt;P&gt;Hi..&lt;/P&gt;

&lt;P&gt;I am trying to create a dashboard which extracts errorCode field from multiple xmls. Xpath for it would be different for different outputs. For ex: for createUser it is abc and for deleteUser it would be  xyz. I need to have the xpath dynamic which extracts errorCode alone. I am trying with below expression which I know makes no sense. Please help.&lt;/P&gt;

&lt;P&gt;|rex "(?.&lt;EM&gt;),(?.&lt;/EM&gt;),(?.&lt;EM&gt;),(?.&lt;/EM&gt;),(?s)(?.*)" | spath input=PAYLOAD output=fault path="*errorCode" |stats count(fault) as FaultCount by fault&lt;/P&gt;

&lt;P&gt;The above is retrieving zero results. &lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 13:57:44 GMT</pubDate>
    <dc:creator>keeplearningbud</dc:creator>
    <dc:date>2020-09-29T13:57:44Z</dc:date>
    <item>
      <title>rex expression to extract field from XML message</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-to-extract-field-from-XML-message/m-p/364333#M107523</link>
      <description>&lt;P&gt;Hi..&lt;/P&gt;

&lt;P&gt;I am trying to create a dashboard which extracts errorCode field from multiple xmls. Xpath for it would be different for different outputs. For ex: for createUser it is abc and for deleteUser it would be  xyz. I need to have the xpath dynamic which extracts errorCode alone. I am trying with below expression which I know makes no sense. Please help.&lt;/P&gt;

&lt;P&gt;|rex "(?.&lt;EM&gt;),(?.&lt;/EM&gt;),(?.&lt;EM&gt;),(?.&lt;/EM&gt;),(?s)(?.*)" | spath input=PAYLOAD output=fault path="*errorCode" |stats count(fault) as FaultCount by fault&lt;/P&gt;

&lt;P&gt;The above is retrieving zero results. &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:57:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-to-extract-field-from-XML-message/m-p/364333#M107523</guid>
      <dc:creator>keeplearningbud</dc:creator>
      <dc:date>2020-09-29T13:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression to extract field from XML message</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-to-extract-field-from-XML-message/m-p/364334#M107524</link>
      <description>&lt;P&gt;If you have multiple different &lt;CODE&gt;XML&lt;/CODE&gt; formats, but the same tag name, then you would probably be better off using a &lt;CODE&gt;rex&lt;/CODE&gt; to extract it, rather than &lt;CODE&gt;spath&lt;/CODE&gt;. &lt;/P&gt;

&lt;P&gt;Try this - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex  "\&amp;lt;errorCode\&amp;gt;\s+?(?&amp;lt;errorCode&amp;gt;\S[^&amp;lt;]+?)\s+?\&amp;lt;\/errorCode\&amp;gt;"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Over at regex101.com that one managed to pull the &lt;CODE&gt;reallygoodstuff&lt;/CODE&gt; out of this one... &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;biggerstuff&amp;gt;  &amp;lt;stuff&amp;gt; we dont care about this  &amp;lt;/stuff&amp;gt; &amp;lt;errorCode&amp;gt; reallygoodstuff &amp;lt;/errorCode&amp;gt; &amp;lt;/biggerstuff&amp;gt;  
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;... and  the&lt;CODE&gt;really good stuff&lt;/CODE&gt; out of this one ...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;biggerstuff&amp;gt; &amp;lt;morestuff&amp;gt; this is just extra &amp;lt;/morestuff&amp;gt; &amp;lt;stuff&amp;gt; we dont care about this  &amp;lt;/stuff&amp;gt; &amp;lt;errorCode&amp;gt; really good stuff &amp;lt;/errorCode&amp;gt; &amp;lt;junk&amp;gt; and I really hate this junk &amp;lt;/junk&amp;gt; &amp;lt;/biggerstuff&amp;gt; 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 May 2017 00:06:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-to-extract-field-from-XML-message/m-p/364334#M107524</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-05-05T00:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression to extract field from XML message</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-to-extract-field-from-XML-message/m-p/364335#M107525</link>
      <description>&lt;P&gt;Sir. Thanks for the reply. But I am unable to apply this to splunk dash board. I am clueless about the mistake.&lt;/P&gt;

&lt;P&gt;host="xyz*" index="abc"  (",log_&lt;EM&gt;," ) | rex "(?.&lt;/EM&gt;),(?.&lt;EM&gt;),(?.&lt;/EM&gt;),(?.&lt;EM&gt;),(?s)(?.&lt;/EM&gt;)" |rex fault=PAYLOAD "\s+?(?\S[^&amp;lt;]+?)\s+?&amp;lt;\/errorCode&amp;gt;"| stats count(fault) as FaultCount by fault&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:57:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-to-extract-field-from-XML-message/m-p/364335#M107525</guid>
      <dc:creator>keeplearningbud</dc:creator>
      <dc:date>2020-09-29T13:57:47Z</dc:date>
    </item>
  </channel>
</rss>

