<?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 How do I extract xml tag using regex? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-xml-tag-using-regex/m-p/94994#M24534</link>
    <description>&lt;P&gt;I tried to extract xml tagNames as fields fieldNameStartTag and fieldNameEndTag using the following.&lt;/P&gt;

&lt;P&gt;rex field=_raw "&amp;lt;(?&lt;FIELDNAMESTARTTAG&gt;.&lt;EM&gt;)&amp;gt;([^&amp;lt;]+)&amp;lt;/(?&lt;FIELDNAMEENDTAG&gt;.&lt;/FIELDNAMEENDTAG&gt;&lt;/EM&gt;)&amp;gt;" &lt;BR /&gt;
But it does not extract all tags correctly. For example I have this xml:&lt;BR /&gt;
&lt;PARENT XSI="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.abcd.com"&gt;&lt;BR /&gt;
  &lt;CHILDONE&gt;abc&lt;/CHILDONE&gt;&lt;BR /&gt;
  &lt;CHILDTWO&gt;xyz&lt;/CHILDTWO&gt;&lt;BR /&gt;
&lt;/PARENT&gt;&lt;/FIELDNAMESTARTTAG&gt;&lt;/P&gt;

&lt;P&gt;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:&lt;BR /&gt;
 1. Parent xmlns:xsi="&lt;A href="http://www.w3.org/2001/XMLSchema-instance"&gt;http://www.w3.org/2001/XMLSchema-instance&lt;/A&gt;" xmlns="&lt;A href="http://www.abcd.com%22%3E"&gt;http://www.abcd.com"&amp;gt;&lt;/A&gt; &lt;CHILDONE&gt;abc&lt;/CHILDONE&gt;&lt;CHILDTWO&gt;&lt;BR /&gt;
 2. ChildOne&amp;gt;&lt;CHILDTWO&gt;xyz&lt;/CHILDTWO&gt;&lt;/CHILDTWO&gt;&lt;/P&gt;

&lt;P&gt;Any help is appreciated.&lt;/P&gt;</description>
    <pubDate>Fri, 16 Mar 2012 16:47:52 GMT</pubDate>
    <dc:creator>merrin</dc:creator>
    <dc:date>2012-03-16T16:47:52Z</dc:date>
    <item>
      <title>How do I extract xml tag using regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-xml-tag-using-regex/m-p/94994#M24534</link>
      <description>&lt;P&gt;I tried to extract xml tagNames as fields fieldNameStartTag and fieldNameEndTag using the following.&lt;/P&gt;

&lt;P&gt;rex field=_raw "&amp;lt;(?&lt;FIELDNAMESTARTTAG&gt;.&lt;EM&gt;)&amp;gt;([^&amp;lt;]+)&amp;lt;/(?&lt;FIELDNAMEENDTAG&gt;.&lt;/FIELDNAMEENDTAG&gt;&lt;/EM&gt;)&amp;gt;" &lt;BR /&gt;
But it does not extract all tags correctly. For example I have this xml:&lt;BR /&gt;
&lt;PARENT XSI="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.abcd.com"&gt;&lt;BR /&gt;
  &lt;CHILDONE&gt;abc&lt;/CHILDONE&gt;&lt;BR /&gt;
  &lt;CHILDTWO&gt;xyz&lt;/CHILDTWO&gt;&lt;BR /&gt;
&lt;/PARENT&gt;&lt;/FIELDNAMESTARTTAG&gt;&lt;/P&gt;

&lt;P&gt;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:&lt;BR /&gt;
 1. Parent xmlns:xsi="&lt;A href="http://www.w3.org/2001/XMLSchema-instance"&gt;http://www.w3.org/2001/XMLSchema-instance&lt;/A&gt;" xmlns="&lt;A href="http://www.abcd.com%22%3E"&gt;http://www.abcd.com"&amp;gt;&lt;/A&gt; &lt;CHILDONE&gt;abc&lt;/CHILDONE&gt;&lt;CHILDTWO&gt;&lt;BR /&gt;
 2. ChildOne&amp;gt;&lt;CHILDTWO&gt;xyz&lt;/CHILDTWO&gt;&lt;/CHILDTWO&gt;&lt;/P&gt;

&lt;P&gt;Any help is appreciated.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2012 16:47:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-xml-tag-using-regex/m-p/94994#M24534</guid>
      <dc:creator>merrin</dc:creator>
      <dc:date>2012-03-16T16:47:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract xml tag using regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-xml-tag-using-regex/m-p/94995#M24535</link>
      <description>&lt;P&gt;Have you checked out the xmlkv command?  This allows you to automatically extract KV pairs from XML formatted data without any regex's:&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/4.3.1/SearchReference/xmlkv"&gt;http://docs.splunk.com/Documentation/Splunk/4.3.1/SearchReference/xmlkv&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2012 18:23:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-xml-tag-using-regex/m-p/94995#M24535</guid>
      <dc:creator>emechler_splunk</dc:creator>
      <dc:date>2012-03-16T18:23:44Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract xml tag using regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-xml-tag-using-regex/m-p/94996#M24536</link>
      <description>&lt;P&gt;You should use the &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath"&gt;&lt;CODE&gt;spath&lt;/CODE&gt;&lt;/A&gt; command, if you're on 4.3 or higher. If you're on older versions, the &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Xmlkv"&gt;&lt;CODE&gt;xmlkv&lt;/CODE&gt;&lt;/A&gt; command will also work for you.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2012 18:46:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-xml-tag-using-regex/m-p/94996#M24536</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2012-03-16T18:46:50Z</dc:date>
    </item>
  </channel>
</rss>

