<?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: How to add and parse the xml data into splunk in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-add-and-parse-the-xml-data-into-splunk/m-p/203696#M98764</link>
    <description>&lt;P&gt;When I have a single row of values with in the tags- &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;employee details="ename;position;branch" department="XYZ"&amp;gt;AA;systems engineer;seattle
 &amp;lt;/employee&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then I'm able to parse the data properly as I require. But when there are multiple rows ( multiple set of values) as mentioned in the above example posted,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;employee details="ename;position;branch" department="XYZ"&amp;gt;BB;Lead;seattle
 CC;Tech Lead;Redmond    
 &amp;lt;/employee&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;then I'm facing difficult to parse the data.&lt;/P&gt;

&lt;P&gt;Example that worked out for me.&lt;/P&gt;

&lt;P&gt;Data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;10:26:10 PST 16 Nov 2015
     &amp;lt;employee details="ename;position;branch" department="XYZ"&amp;gt;AA;systems engineer;seattle
 &amp;lt;/employee&amp;gt;

 1:26:10 PST 16 Nov 2015
     &amp;lt;employee details="ename;position;branch" department="XYZ"&amp;gt;BB;Lead;seattle
 &amp;lt;/employee&amp;gt;

 6:26:10 PST 16 Nov 2015
     &amp;lt;employee details="ename;position;branch" department="XYZ"&amp;gt;DD;data architect;annapolis
 &amp;lt;/employee&amp;gt;

props.conf

[employee]
SHOULD_LINEMERGE = true (combines multiple lines into single event)
MUST_BREAK_AFTER  = &amp;lt;/employee&amp;gt;    (dividing the data into events)
NO_BINARY_CHECK = true
disabled = false
pulldown_type = true
REPORT-employee = emp   (transform stanza name)

transforms.conf

[emp]
REGEX = &amp;lt;employee details="ename,position,branch" department="XYZ"&amp;gt;(.*?)&amp;lt;/employee&amp;gt;  (regular expression for capturing the data within the tags)
FORMAT = details::$1 (format of the event)
MV_ADD = true (multivalued field)
REPEAT_MATCH = true

CSV data formatting

Splunk Query: 

index = main sourcetype = employee | eval data = split(details,";") | eval name= mvindex(data,0) | eval position = mvindex(data,-2) | eval branch= mvindex(data,-1) | table data, name, position , branch
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ename        position                          branch
 AA           systems engineer              seattle
 BB           Lead                                    seattle 
 DD           data architect                  annapolis
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 31 Dec 2015 19:54:05 GMT</pubDate>
    <dc:creator>smusunuri</dc:creator>
    <dc:date>2015-12-31T19:54:05Z</dc:date>
    <item>
      <title>How to add and parse the xml data into splunk</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-add-and-parse-the-xml-data-into-splunk/m-p/203693#M98761</link>
      <description>&lt;P&gt;Structure of the XML file looks like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;10:26:10 PST 16 Nov 2015
    &amp;lt;employee details="ename;position;branch" department="XYZ"&amp;gt;AA;systems engineer;seattle
&amp;lt;/employee&amp;gt;

1:26:10 PST 16 Nov 2015
    &amp;lt;employee details="ename;position;branch" department="XYZ"&amp;gt;BB;Lead;seattle
CC;Tech Lead,Redmond    
&amp;lt;/employee&amp;gt;

6:26:10 PST 16 Nov 2015
    &amp;lt;employee details="ename;position;branch" department="XYZ"&amp;gt;DD;data architect;annapolis
&amp;lt;/employee&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I need the output as:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ename        position            branch
AA           systems engineer    seattle
BB           Lead                seattle
CC           Tech Lead           Redmond    
DD           data architect      annapolis
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Dec 2015 00:15:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-add-and-parse-the-xml-data-into-splunk/m-p/203693#M98761</guid>
      <dc:creator>smusunuri</dc:creator>
      <dc:date>2015-12-31T00:15:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to add and parse the xml data into splunk</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-add-and-parse-the-xml-data-into-splunk/m-p/203694#M98762</link>
      <description>&lt;P&gt;The following &lt;CODE&gt;SEDCMD&lt;/CODE&gt; will remove unwanted xml tags and refer to the delim stanza in &lt;CODE&gt;transforms&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;SEDCMD-removeunwanted=s/(\&amp;lt;.*\&amp;gt;)(.*)(\W.*\&amp;gt;)/$2/g
REPORT-extractfields=extract_fields
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;See &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.0/Data/Anonymizedatausingconfigurationfiles"&gt;http://docs.splunk.com/Documentation/Splunk/6.2.0/Data/Anonymizedatausingconfigurationfiles&lt;/A&gt;  for details&lt;/P&gt;

&lt;P&gt;And add the following to your &lt;CODE&gt;transforms&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[extract_fields]
DELIMS = ";"
FIELDS = "ename", "position", "branch"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.0/admin/Transformsconf"&gt;http://docs.splunk.com/Documentation/Splunk/6.2.0/admin/Transformsconf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Dec 2015 01:41:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-add-and-parse-the-xml-data-into-splunk/m-p/203694#M98762</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2015-12-31T01:41:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to add and parse the xml data into splunk</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-add-and-parse-the-xml-data-into-splunk/m-p/203695#M98763</link>
      <description>&lt;P&gt;Actually I didn't work for me. Data with in tagsis not accepted by using $2. I'm getting output as &lt;/P&gt;

&lt;P&gt;ename&lt;BR /&gt;
10:26:10 PST 16 Nov 2015 $2&lt;BR /&gt;
1:26:10 PST 16 Nov 2015 $2&lt;BR /&gt;
 6:26:10 PST 16 Nov 2015 $2&lt;/P&gt;</description>
      <pubDate>Thu, 31 Dec 2015 19:46:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-add-and-parse-the-xml-data-into-splunk/m-p/203695#M98763</guid>
      <dc:creator>smusunuri</dc:creator>
      <dc:date>2015-12-31T19:46:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to add and parse the xml data into splunk</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-add-and-parse-the-xml-data-into-splunk/m-p/203696#M98764</link>
      <description>&lt;P&gt;When I have a single row of values with in the tags- &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;employee details="ename;position;branch" department="XYZ"&amp;gt;AA;systems engineer;seattle
 &amp;lt;/employee&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then I'm able to parse the data properly as I require. But when there are multiple rows ( multiple set of values) as mentioned in the above example posted,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;employee details="ename;position;branch" department="XYZ"&amp;gt;BB;Lead;seattle
 CC;Tech Lead;Redmond    
 &amp;lt;/employee&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;then I'm facing difficult to parse the data.&lt;/P&gt;

&lt;P&gt;Example that worked out for me.&lt;/P&gt;

&lt;P&gt;Data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;10:26:10 PST 16 Nov 2015
     &amp;lt;employee details="ename;position;branch" department="XYZ"&amp;gt;AA;systems engineer;seattle
 &amp;lt;/employee&amp;gt;

 1:26:10 PST 16 Nov 2015
     &amp;lt;employee details="ename;position;branch" department="XYZ"&amp;gt;BB;Lead;seattle
 &amp;lt;/employee&amp;gt;

 6:26:10 PST 16 Nov 2015
     &amp;lt;employee details="ename;position;branch" department="XYZ"&amp;gt;DD;data architect;annapolis
 &amp;lt;/employee&amp;gt;

props.conf

[employee]
SHOULD_LINEMERGE = true (combines multiple lines into single event)
MUST_BREAK_AFTER  = &amp;lt;/employee&amp;gt;    (dividing the data into events)
NO_BINARY_CHECK = true
disabled = false
pulldown_type = true
REPORT-employee = emp   (transform stanza name)

transforms.conf

[emp]
REGEX = &amp;lt;employee details="ename,position,branch" department="XYZ"&amp;gt;(.*?)&amp;lt;/employee&amp;gt;  (regular expression for capturing the data within the tags)
FORMAT = details::$1 (format of the event)
MV_ADD = true (multivalued field)
REPEAT_MATCH = true

CSV data formatting

Splunk Query: 

index = main sourcetype = employee | eval data = split(details,";") | eval name= mvindex(data,0) | eval position = mvindex(data,-2) | eval branch= mvindex(data,-1) | table data, name, position , branch
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ename        position                          branch
 AA           systems engineer              seattle
 BB           Lead                                    seattle 
 DD           data architect                  annapolis
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Dec 2015 19:54:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-add-and-parse-the-xml-data-into-splunk/m-p/203696#M98764</guid>
      <dc:creator>smusunuri</dc:creator>
      <dc:date>2015-12-31T19:54:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to add and parse the xml data into splunk</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-add-and-parse-the-xml-data-into-splunk/m-p/203697#M98765</link>
      <description>&lt;P&gt;Not sure I understand your comment "When I have a single row of values with in the tags"? Can you share an example of when it doesn't work&lt;/P&gt;</description>
      <pubDate>Thu, 31 Dec 2015 20:12:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-add-and-parse-the-xml-data-into-splunk/m-p/203697#M98765</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2015-12-31T20:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to add and parse the xml data into splunk</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-add-and-parse-the-xml-data-into-splunk/m-p/203698#M98766</link>
      <description>&lt;P&gt;See above. Modified my comment.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Dec 2015 20:15:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-add-and-parse-the-xml-data-into-splunk/m-p/203698#M98766</guid>
      <dc:creator>smusunuri</dc:creator>
      <dc:date>2015-12-31T20:15:27Z</dc:date>
    </item>
  </channel>
</rss>

