<?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 extract fields from XML maintaining alignment if same tags are repeated? in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/how-extract-fields-from-XML-maintaining-alignment-if-same-tags/m-p/446833#M29365</link>
    <description>&lt;P&gt;@marcoemme41, ideally if you are interested in &lt;CODE&gt;&amp;lt;book&amp;gt;&lt;/CODE&gt; being the root node of individual events and not &lt;CODE&gt;&amp;lt;purchases&amp;gt;&lt;/CODE&gt; you should try to index only &lt;CODE&gt;&amp;lt;book&amp;gt;&lt;/CODE&gt; node and discard &lt;CODE&gt;&amp;lt;publisher&amp;gt;&lt;/CODE&gt; node by pushing to null queue:&lt;BR /&gt;
&lt;STRONG&gt;props.conf&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;BREAK_ONLY_BEFORE=\&amp;lt;book\&amp;gt;
MUST_BREAK_AFTER=\&amp;lt;\/book\&amp;gt;
KV_MODE=xml
TRANSFORMS-nullQueueDiscardPurchases=nullQueueDiscardPurchases
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;transforms.conf&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[nullQueueDiscardPurchases]
REGEX = purchases
DEST_KEY = queue
FORMAT = nullQueue
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, as per your question following is &lt;CODE&gt;searchtime&lt;/CODE&gt;. Consider this only as workaround, since, ideal way would to ingest the data in proper way as expected.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw="
&amp;lt;purchases&amp;gt;
  &amp;lt;book&amp;gt;
    &amp;lt;author&amp;gt;Martin&amp;lt;/author&amp;gt;
    &amp;lt;title&amp;gt;A Game of Thrones&amp;lt;/title&amp;gt;
    &amp;lt;title&amp;gt;A Clash of Kings&amp;lt;/title&amp;gt;
  &amp;lt;/book&amp;gt;
  &amp;lt;book&amp;gt;
    &amp;lt;author&amp;gt;Clarke&amp;lt;/author&amp;gt;
    &amp;lt;title&amp;gt;Jonathan Strange&amp;lt;/title&amp;gt;
  &amp;lt;/book&amp;gt;
&amp;lt;/purchases&amp;gt;"
| spath input=_raw path=purchases
| eval purchases=replace(purchases,"&amp;lt;/book&amp;gt;","&amp;lt;/book&amp;gt;|")
| makemv purchases delim="|"
| mvexpand purchases
| rename purchases as _raw
| spath
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 17 Mar 2019 15:18:17 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2019-03-17T15:18:17Z</dc:date>
    <item>
      <title>how extract fields from XML maintaining alignment if same tags are repeated?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/how-extract-fields-from-XML-maintaining-alignment-if-same-tags/m-p/446832#M29364</link>
      <description>&lt;P&gt;I have an XML with some tags repetead and other tags not repeated.  I need extract all fields from this XML maintaining corrispondence between all tags. &lt;/P&gt;

&lt;P&gt;I can explain using the example reported in Splunk docs for spath command (&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.4/SearchReference/Spath):"&gt;https://docs.splunk.com/Documentation/Splunk/7.2.4/SearchReference/Spath):&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;This is my XML and the query to extract fields:&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/6726i9956C89E23DF0251/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;The output of this query is:&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/6727i022B61BFAA2F2B81/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;This is wrong because "Clarke" is associated to "A Clash of Kings" instead to "Jonathan Strange".&lt;BR /&gt;
What I need, instead, is Martin repeated in the first and second lines of Author column, and Clarke written in third line.&lt;/P&gt;

&lt;P&gt;Someone can help me?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2019 17:31:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/how-extract-fields-from-XML-maintaining-alignment-if-same-tags/m-p/446832#M29364</guid>
      <dc:creator>marcoemme41</dc:creator>
      <dc:date>2019-03-15T17:31:46Z</dc:date>
    </item>
    <item>
      <title>Re: how extract fields from XML maintaining alignment if same tags are repeated?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/how-extract-fields-from-XML-maintaining-alignment-if-same-tags/m-p/446833#M29365</link>
      <description>&lt;P&gt;@marcoemme41, ideally if you are interested in &lt;CODE&gt;&amp;lt;book&amp;gt;&lt;/CODE&gt; being the root node of individual events and not &lt;CODE&gt;&amp;lt;purchases&amp;gt;&lt;/CODE&gt; you should try to index only &lt;CODE&gt;&amp;lt;book&amp;gt;&lt;/CODE&gt; node and discard &lt;CODE&gt;&amp;lt;publisher&amp;gt;&lt;/CODE&gt; node by pushing to null queue:&lt;BR /&gt;
&lt;STRONG&gt;props.conf&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;BREAK_ONLY_BEFORE=\&amp;lt;book\&amp;gt;
MUST_BREAK_AFTER=\&amp;lt;\/book\&amp;gt;
KV_MODE=xml
TRANSFORMS-nullQueueDiscardPurchases=nullQueueDiscardPurchases
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;transforms.conf&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[nullQueueDiscardPurchases]
REGEX = purchases
DEST_KEY = queue
FORMAT = nullQueue
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, as per your question following is &lt;CODE&gt;searchtime&lt;/CODE&gt;. Consider this only as workaround, since, ideal way would to ingest the data in proper way as expected.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw="
&amp;lt;purchases&amp;gt;
  &amp;lt;book&amp;gt;
    &amp;lt;author&amp;gt;Martin&amp;lt;/author&amp;gt;
    &amp;lt;title&amp;gt;A Game of Thrones&amp;lt;/title&amp;gt;
    &amp;lt;title&amp;gt;A Clash of Kings&amp;lt;/title&amp;gt;
  &amp;lt;/book&amp;gt;
  &amp;lt;book&amp;gt;
    &amp;lt;author&amp;gt;Clarke&amp;lt;/author&amp;gt;
    &amp;lt;title&amp;gt;Jonathan Strange&amp;lt;/title&amp;gt;
  &amp;lt;/book&amp;gt;
&amp;lt;/purchases&amp;gt;"
| spath input=_raw path=purchases
| eval purchases=replace(purchases,"&amp;lt;/book&amp;gt;","&amp;lt;/book&amp;gt;|")
| makemv purchases delim="|"
| mvexpand purchases
| rename purchases as _raw
| spath
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 17 Mar 2019 15:18:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/how-extract-fields-from-XML-maintaining-alignment-if-same-tags/m-p/446833#M29365</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-03-17T15:18:17Z</dc:date>
    </item>
  </channel>
</rss>

