<?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 attributes from XML Schema in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Extracting-attributes-from-XML-Schema/m-p/293340#M18635</link>
    <description>&lt;P&gt;I know there has to be a nice way to do this upon indexing in Splunk...I have a large XML file that I am indexing on the tag &lt;EM&gt;info&lt;/EM&gt; however when each event is index I want some information from higher up the "tree" of the XML to be placed into that event.  For a small example in:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;Baseball&amp;gt;
         &amp;lt;player name="freese" number="23"&amp;gt;
             &amp;lt;stats&amp;gt;
                       &amp;lt;info index=0&amp;gt;
                           &amp;lt;Team&amp;gt;Pittsburgh Pirates&amp;lt;/Team&amp;gt;
                           &amp;lt;BA&amp;gt;.249&amp;lt;/BA&amp;gt;
                       &amp;lt;/info&amp;gt;
                       &amp;lt;info index=1&amp;gt;
                          &amp;lt;Team&amp;gt;Cardinals&amp;lt;/Team&amp;gt;
                          &amp;lt;BA&amp;gt;.248&amp;lt;/BA&amp;gt;
            &amp;lt;/stats&amp;gt;
        &amp;lt;/player&amp;gt;
         &amp;lt;player name="Pujols" number="5"&amp;gt;
             &amp;lt;stats&amp;gt;
                       &amp;lt;info index=0&amp;gt;
                           &amp;lt;Team&amp;gt;LA Angles&amp;lt;/Team&amp;gt;
                           &amp;lt;BA&amp;gt;.236&amp;lt;/BA&amp;gt;
                       &amp;lt;/info&amp;gt;
                       &amp;lt;info index=1&amp;gt;
                          &amp;lt;Team&amp;gt;Cardinals&amp;lt;/Team&amp;gt;
                          &amp;lt;BA&amp;gt;.307&amp;lt;/BA&amp;gt;
            &amp;lt;/stats&amp;gt;
        &amp;lt;/player&amp;gt;
    &amp;lt;/Baseball&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I would like to have events that have all the information in the &lt;EM&gt;info&lt;/EM&gt; tag as well as the two attributes of player &lt;EM&gt;name&lt;/EM&gt; and &lt;EM&gt;number&lt;/EM&gt;.   Any ideas would be greatly appreciated.  &lt;/P&gt;</description>
    <pubDate>Fri, 30 Jun 2017 22:08:32 GMT</pubDate>
    <dc:creator>amanno</dc:creator>
    <dc:date>2017-06-30T22:08:32Z</dc:date>
    <item>
      <title>Extracting attributes from XML Schema</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Extracting-attributes-from-XML-Schema/m-p/293340#M18635</link>
      <description>&lt;P&gt;I know there has to be a nice way to do this upon indexing in Splunk...I have a large XML file that I am indexing on the tag &lt;EM&gt;info&lt;/EM&gt; however when each event is index I want some information from higher up the "tree" of the XML to be placed into that event.  For a small example in:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;Baseball&amp;gt;
         &amp;lt;player name="freese" number="23"&amp;gt;
             &amp;lt;stats&amp;gt;
                       &amp;lt;info index=0&amp;gt;
                           &amp;lt;Team&amp;gt;Pittsburgh Pirates&amp;lt;/Team&amp;gt;
                           &amp;lt;BA&amp;gt;.249&amp;lt;/BA&amp;gt;
                       &amp;lt;/info&amp;gt;
                       &amp;lt;info index=1&amp;gt;
                          &amp;lt;Team&amp;gt;Cardinals&amp;lt;/Team&amp;gt;
                          &amp;lt;BA&amp;gt;.248&amp;lt;/BA&amp;gt;
            &amp;lt;/stats&amp;gt;
        &amp;lt;/player&amp;gt;
         &amp;lt;player name="Pujols" number="5"&amp;gt;
             &amp;lt;stats&amp;gt;
                       &amp;lt;info index=0&amp;gt;
                           &amp;lt;Team&amp;gt;LA Angles&amp;lt;/Team&amp;gt;
                           &amp;lt;BA&amp;gt;.236&amp;lt;/BA&amp;gt;
                       &amp;lt;/info&amp;gt;
                       &amp;lt;info index=1&amp;gt;
                          &amp;lt;Team&amp;gt;Cardinals&amp;lt;/Team&amp;gt;
                          &amp;lt;BA&amp;gt;.307&amp;lt;/BA&amp;gt;
            &amp;lt;/stats&amp;gt;
        &amp;lt;/player&amp;gt;
    &amp;lt;/Baseball&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I would like to have events that have all the information in the &lt;EM&gt;info&lt;/EM&gt; tag as well as the two attributes of player &lt;EM&gt;name&lt;/EM&gt; and &lt;EM&gt;number&lt;/EM&gt;.   Any ideas would be greatly appreciated.  &lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2017 22:08:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Extracting-attributes-from-XML-Schema/m-p/293340#M18635</guid>
      <dc:creator>amanno</dc:creator>
      <dc:date>2017-06-30T22:08:32Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting attributes from XML Schema</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Extracting-attributes-from-XML-Schema/m-p/293341#M18636</link>
      <description>&lt;P&gt;First off, your sample XML seem to have &lt;STRONG&gt;info&lt;/STRONG&gt; end tags missing. You can use &lt;STRONG&gt;spath&lt;/STRONG&gt; or &lt;STRONG&gt;xpath&lt;/STRONG&gt; command to extract fields from XML. Based on the your needs you can extract individual field or as multi valued fields.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval xml_data="&amp;lt;Baseball&amp;gt;
  &amp;lt;player name=\"freese\" number=\"23\"&amp;gt;
      &amp;lt;stats&amp;gt;
        &amp;lt;info index=0&amp;gt;
            &amp;lt;Team&amp;gt;Pittsburgh Pirates&amp;lt;/Team&amp;gt;
            &amp;lt;BA&amp;gt;.249&amp;lt;/BA&amp;gt;
        &amp;lt;/info&amp;gt;
        &amp;lt;info index=1&amp;gt;
           &amp;lt;Team&amp;gt;Cardinals&amp;lt;/Team&amp;gt;
           &amp;lt;BA&amp;gt;.248&amp;lt;/BA&amp;gt;
        &amp;lt;/info&amp;gt;
     &amp;lt;/stats&amp;gt;
  &amp;lt;/player&amp;gt;
  &amp;lt;player name=\"Pujols\" number=\"5\"&amp;gt;
    &amp;lt;stats&amp;gt;
        &amp;lt;info index=0&amp;gt;
            &amp;lt;Team&amp;gt;LA Angles&amp;lt;/Team&amp;gt;
            &amp;lt;BA&amp;gt;.236&amp;lt;/BA&amp;gt;
        &amp;lt;/info&amp;gt;
        &amp;lt;info index=1&amp;gt;
           &amp;lt;Team&amp;gt;Cardinals&amp;lt;/Team&amp;gt;
           &amp;lt;BA&amp;gt;.307&amp;lt;/BA&amp;gt;
        &amp;lt;/info&amp;gt;
    &amp;lt;/stats&amp;gt;
  &amp;lt;/player&amp;gt;
 &amp;lt;/Baseball&amp;gt;"
 | spath input=xml_data path=Baseball.player{1}{@name} output=name
 | spath input=xml_data path=Baseball.player{1}{@number} output=number
 | spath input=xml_data path=Baseball.player{@name} output=names
 | spath input=xml_data path=Baseball.player{@number} output=numbers
 | spath input=xml_data path=Baseball.player.stats.info.Team output=Team
 | spath input=xml_data path=Baseball.player.stats.info.BA output=BA
 | table xml_data name names number numbers Team BA
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Refer to Splunk documentation for more details: &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Jul 2017 08:47:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Extracting-attributes-from-XML-Schema/m-p/293341#M18636</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-07-01T08:47:39Z</dc:date>
    </item>
  </channel>
</rss>

