<?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: XML nested field issues in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/XML-nested-field-issues/m-p/345392#M170351</link>
    <description>&lt;P&gt;Usually you should Start by adding only one pipe at time to see how it is working.&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;The spath Query gets all the NodeIds under Query and then second spath gets their Names.&lt;/LI&gt;
&lt;LI&gt;The &lt;CODE&gt;mvzip()&lt;/CODE&gt; function stitches the multivalued fields together one by one. By default it puts a comma 1&lt;CODE&gt;,&lt;/CODE&gt; between the zipped values. You can specify optional third parameter for &lt;CODE&gt;mvzip()&lt;/CODE&gt; to specify any other delimiter string.&lt;/LI&gt;
&lt;LI&gt;I had used makemv command to convert expanded data ti multivalue based on command delimeter field as stated above. Seems like &lt;CODE&gt;&amp;lt;/Result&amp;gt;&lt;/CODE&gt; is working for you.&lt;/LI&gt;
&lt;LI&gt;mvindex() function reads data from multivalue field based on its index starting from 0. In our case 1st index i.e. &lt;CODE&gt;0&lt;/CODE&gt; is &lt;CODE&gt;Query&lt;/CODE&gt; and 2nd Index i.e. &lt;CODE&gt;1&lt;/CODE&gt; is Query Name.&lt;/LI&gt;
&lt;LI&gt;Finally I am using &lt;CODE&gt;rex&lt;/CODE&gt;command to extract NodeId with &lt;CODE&gt;max_match=0&lt;/CODE&gt; to fetch unlimited results. If you have some upper limit to the NodeIds you can mention that number instead.&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Refer to Splunk Documentation for multi value eval functions: &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/MultivalueEvalFunctions"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/MultivalueEvalFunctions&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Hope this clarifies... Don't forget to up vote the comment/s that helped &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 16 Apr 2018 16:49:33 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2018-04-16T16:49:33Z</dc:date>
    <item>
      <title>XML nested field issues</title>
      <link>https://community.splunk.com/t5/Splunk-Search/XML-nested-field-issues/m-p/345387#M170346</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;

&lt;P&gt;I have a XML file like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;CxXMLResult&amp;gt;
    &amp;lt;Query name="Stored_XSS"&amp;gt;
        &amp;lt;Result NodeId="1"&amp;gt;
        &amp;lt;/Result&amp;gt;
        &amp;lt;Result  NodeId="2"&amp;gt;
        &amp;lt;/Result&amp;gt;
        &amp;lt;Result  NodeId="3"&amp;gt;
        &amp;lt;/Result&amp;gt;
    &amp;lt;/Query&amp;gt;
&amp;lt;CxXMLResult&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So number of result tag actually represents number of vulnerability by Query. &lt;/P&gt;

&lt;P&gt;When I search like : &lt;CODE&gt;index="deneme_index6" CxXMLResult.Query{@name}=* | stats count(CxXMLResult.Query{@name})&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Returns &lt;BR /&gt;
&lt;CODE&gt;CxXMLResult.Query{@name}    | count &lt;BR /&gt;
 Stored_XSS                        1&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;But actually, There are three Stored_XSS because there are three Result tag under the Query of Stored_XSS.&lt;/P&gt;

&lt;P&gt;So I search like: &lt;CODE&gt;index="deneme_index6" | spath output=result path=CxXMLResults.Query | mvexpand result | table result | spath input=result output=NodeID path=Result{@NodeId} | stats count(NodeID) by result&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I can count Result tags under each Query separetly. But I lose Query's name. How can i add Query's name in my table.&lt;/P&gt;

&lt;P&gt;My Splunk Screen like:&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/239579-search1.png" alt="alt text" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:06:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/XML-nested-field-issues/m-p/345387#M170346</guid>
      <dc:creator>rasty</dc:creator>
      <dc:date>2020-09-29T19:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: XML nested field issues</title>
      <link>https://community.splunk.com/t5/Splunk-Search/XML-nested-field-issues/m-p/345388#M170347</link>
      <description>&lt;P&gt;@rasty, following is a run anywhere example based on sample data/query provided. You will need query from spath onward. Please try out and confirm!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw=" &amp;lt;CxXMLResult&amp;gt;
     &amp;lt;Query name=\"Stored_XSS\"&amp;gt;
         &amp;lt;Result NodeId=\"1\"&amp;gt;
         &amp;lt;/Result&amp;gt;
         &amp;lt;Result  NodeId=\"2\"&amp;gt;
         &amp;lt;/Result&amp;gt;
         &amp;lt;Result  NodeId=\"3\"&amp;gt;
         &amp;lt;/Result&amp;gt;
     &amp;lt;/Query&amp;gt;
 &amp;lt;CxXMLResult&amp;gt;"
 | spath output=QueryName path="CxXMLResult.Query{@name}"
 | spath output=QueryResults path="CxXMLResult.Query.Result{@NodeId}"
 | eval VulnerabilityCount=mvcount(QueryResults)
 | table QueryName VulnerabilityCount
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Apr 2018 09:46:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/XML-nested-field-issues/m-p/345388#M170347</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-04-16T09:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: XML nested field issues</title>
      <link>https://community.splunk.com/t5/Splunk-Search/XML-nested-field-issues/m-p/345389#M170348</link>
      <description>&lt;P&gt;Hi niketnilay, &lt;/P&gt;

&lt;P&gt;it will not work as desired. Because for example, &lt;/P&gt;

&lt;P&gt;XML like: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;CxXMLResult&amp;gt;
      &amp;lt;Query name="Stored_XSS"&amp;gt;
          &amp;lt;Result NodeId="1"&amp;gt;
          &amp;lt;/Result&amp;gt;
          &amp;lt;Result  NodeId="2"&amp;gt;
          &amp;lt;/Result&amp;gt;
          &amp;lt;Result  NodeId="3"&amp;gt;
          &amp;lt;/Result&amp;gt;
      &amp;lt;/Query&amp;gt;
      &amp;lt;Query name="Use_Of_Hardcoded_Password"&amp;gt;
          &amp;lt;Result NodeId="1"&amp;gt;
          &amp;lt;/Result&amp;gt;
          &amp;lt;Result  NodeId="2"&amp;gt;
          &amp;lt;/Result&amp;gt;
          &amp;lt;Result  NodeId="3"&amp;gt;
          &amp;lt;/Result&amp;gt;
      &amp;lt;/Query&amp;gt;
  &amp;lt;CxXMLResult&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So when I do &lt;CODE&gt;| spath output=QueryResults path="CxXMLResult.Query.Result{@NodeId}"&lt;BR /&gt;
  | eval VulnerabilityCount=mvcount(QueryResults)&lt;BR /&gt;
  | table QueryName VulnerabilityCount&lt;/CODE&gt; VulnerabilityCount will take value of six. Because all of CxXMLResult in one event. But I want to Stored_XSS 3 and Use_Of_Hardcoded_Password 3.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:06:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/XML-nested-field-issues/m-p/345389#M170348</guid>
      <dc:creator>rasty</dc:creator>
      <dc:date>2020-09-29T19:06:11Z</dc:date>
    </item>
    <item>
      <title>Re: XML nested field issues</title>
      <link>https://community.splunk.com/t5/Splunk-Search/XML-nested-field-issues/m-p/345390#M170349</link>
      <description>&lt;P&gt;@rasty please try the following answer with run anywhere example&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw="&amp;lt;CxXMLResult&amp;gt;
       &amp;lt;Query name=\"Stored_XSS\"&amp;gt;
           &amp;lt;Result NodeId=\"1\"&amp;gt;
           &amp;lt;/Result&amp;gt;
           &amp;lt;Result  NodeId=\"2\"&amp;gt;
           &amp;lt;/Result&amp;gt;
           &amp;lt;Result  NodeId=\"3\"&amp;gt;
           &amp;lt;/Result&amp;gt;
       &amp;lt;/Query&amp;gt;
       &amp;lt;Query name=\"Use_Of_Hardcoded_Password\"&amp;gt;
           &amp;lt;Result NodeId=\"1\"&amp;gt;
           &amp;lt;/Result&amp;gt;
           &amp;lt;Result  NodeId=\"2\"&amp;gt;
           &amp;lt;/Result&amp;gt;
       &amp;lt;/Query&amp;gt;
   &amp;lt;CxXMLResult&amp;gt;"
 | spath output=Query path="CxXMLResult.Query"
 | spath output=QueryName path="CxXMLResult.Query{@name}"
 | fields - _*
 | eval Data= mvzip(Query,QueryName)
 | fields Data
 | mvexpand Data
 | makemv delim="," Data
 | eval QueryName=mvindex(Data,1),Query=mvindex(Data,0)
 | fields - Data
 | rex field=Query "NodeId=\"(?&amp;lt;NodeId&amp;gt;[^\"]+)\"" max_match=0
 | eval count=mvcount(NodeId)
 | fields QueryName NodeId count
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Apr 2018 13:57:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/XML-nested-field-issues/m-p/345390#M170349</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-04-16T13:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: XML nested field issues</title>
      <link>https://community.splunk.com/t5/Splunk-Search/XML-nested-field-issues/m-p/345391#M170350</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| spath output=Query path="CxXMLResults.Query"
  | spath output=QueryName path="CxXMLResults.Query{@name}"
  | fields - _*
  | eval Data= mvzip(Query,QueryName)
  | fields Data
  | mvexpand Data
  | makemv delim="&amp;lt;/Result&amp;gt;," Data
  | eval QueryName=mvindex(Data,1),Query=mvindex(Data,0)
  | fields - Data
  | rex field=Query "NodeId=\"(?&amp;lt;NodeId&amp;gt;[^\"]+)\"" max_match=0
  | stats count(NodeId) by QueryName
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is work for me Thank you for all help niketnilay. &lt;/P&gt;

&lt;P&gt;Can you explain steps ? Because I really want to learn everythings  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; I am new in my carrier&lt;/P&gt;

&lt;P&gt;Regards..&lt;/P&gt;</description>
      <pubDate>Mon, 16 Apr 2018 16:35:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/XML-nested-field-issues/m-p/345391#M170350</guid>
      <dc:creator>rasty</dc:creator>
      <dc:date>2018-04-16T16:35:14Z</dc:date>
    </item>
    <item>
      <title>Re: XML nested field issues</title>
      <link>https://community.splunk.com/t5/Splunk-Search/XML-nested-field-issues/m-p/345392#M170351</link>
      <description>&lt;P&gt;Usually you should Start by adding only one pipe at time to see how it is working.&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;The spath Query gets all the NodeIds under Query and then second spath gets their Names.&lt;/LI&gt;
&lt;LI&gt;The &lt;CODE&gt;mvzip()&lt;/CODE&gt; function stitches the multivalued fields together one by one. By default it puts a comma 1&lt;CODE&gt;,&lt;/CODE&gt; between the zipped values. You can specify optional third parameter for &lt;CODE&gt;mvzip()&lt;/CODE&gt; to specify any other delimiter string.&lt;/LI&gt;
&lt;LI&gt;I had used makemv command to convert expanded data ti multivalue based on command delimeter field as stated above. Seems like &lt;CODE&gt;&amp;lt;/Result&amp;gt;&lt;/CODE&gt; is working for you.&lt;/LI&gt;
&lt;LI&gt;mvindex() function reads data from multivalue field based on its index starting from 0. In our case 1st index i.e. &lt;CODE&gt;0&lt;/CODE&gt; is &lt;CODE&gt;Query&lt;/CODE&gt; and 2nd Index i.e. &lt;CODE&gt;1&lt;/CODE&gt; is Query Name.&lt;/LI&gt;
&lt;LI&gt;Finally I am using &lt;CODE&gt;rex&lt;/CODE&gt;command to extract NodeId with &lt;CODE&gt;max_match=0&lt;/CODE&gt; to fetch unlimited results. If you have some upper limit to the NodeIds you can mention that number instead.&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Refer to Splunk Documentation for multi value eval functions: &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/MultivalueEvalFunctions"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/MultivalueEvalFunctions&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Hope this clarifies... Don't forget to up vote the comment/s that helped &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Apr 2018 16:49:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/XML-nested-field-issues/m-p/345392#M170351</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-04-16T16:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: XML nested field issues</title>
      <link>https://community.splunk.com/t5/Splunk-Search/XML-nested-field-issues/m-p/345393#M170352</link>
      <description>&lt;P&gt;Really, thank you so much niketnilay for everything &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Apr 2018 17:07:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/XML-nested-field-issues/m-p/345393#M170352</guid>
      <dc:creator>rasty</dc:creator>
      <dc:date>2018-04-16T17:07:28Z</dc:date>
    </item>
  </channel>
</rss>

