<?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: Extracting multiple attribute name value pair from XML? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-attribute-name-value-pair-from-XML/m-p/621631#M216078</link>
    <description>&lt;P&gt;You can use spath then foreach to make the attribute/name values to their respective fields.&lt;/P&gt;&lt;P&gt;Note your original XML is malformed - you are missing "/" character on closing OrderAttributeValue and you have an extra &amp;gt; after your OrderRef.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="&amp;lt;RECORD&amp;gt;
   &amp;lt;ORDER&amp;gt;
      &amp;lt;OrderDate&amp;gt;21-11-2022&amp;lt;/OrderDate&amp;gt;
      &amp;lt;OrderRef&amp;gt;12345678&amp;lt;/OrderRef&amp;gt;
      &amp;lt;OrderAttributes&amp;gt;
         &amp;lt;OrderAttributeName&amp;gt;Attribute1&amp;lt;/OrderAttributeName&amp;gt;
         &amp;lt;OrderAttributeValue&amp;gt;Value1&amp;lt;/OrderAttributeValue&amp;gt;
         &amp;lt;OrderAttributeName&amp;gt;Attribute2&amp;lt;/OrderAttributeName&amp;gt;
         &amp;lt;OrderAttributeValue&amp;gt;Value2&amp;lt;/OrderAttributeValue&amp;gt;
         &amp;lt;OrderAttributeName&amp;gt;Attribute3&amp;lt;/OrderAttributeName&amp;gt;
         &amp;lt;OrderAttributeValue&amp;gt;Value3&amp;lt;/OrderAttributeValue&amp;gt;
      &amp;lt;/OrderAttributes&amp;gt;
   &amp;lt;/ORDER&amp;gt;
&amp;lt;/RECORD&amp;gt;"

| spath
| rename RECORD.ORDER.* as *
| foreach 0 1 2 3 4  [ eval f=mvindex('OrderAttributes.OrderAttributeName', &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;), {f}=mvindex('OrderAttributes.OrderAttributeValue', &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;) ]
| table OrderDate OrderRef Attribute*&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;The numbers in the foreach will determine how many possible attributes this can handle&lt;/P&gt;</description>
    <pubDate>Mon, 21 Nov 2022 22:50:28 GMT</pubDate>
    <dc:creator>bowesmana</dc:creator>
    <dc:date>2022-11-21T22:50:28Z</dc:date>
    <item>
      <title>How to extract multiple attribute name value pair from XML?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-attribute-name-value-pair-from-XML/m-p/621620#M216075</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Our system holds XML logs and the way it is structured, some of values are held inside a common set of name/value attribute pair which repeats number of times within the XML.&lt;/P&gt;
&lt;P&gt;Index name is 'applogs'.&lt;/P&gt;
&lt;P&gt;Example XML:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;&amp;lt;RECORD&amp;gt;
   &amp;lt;ORDER&amp;gt;
      &amp;lt;OrderDate&amp;gt;21-11-2022&amp;lt;/OrderDate&amp;gt;
      &amp;lt;OrderRef&amp;gt;12345678&amp;gt;&amp;lt;/OrderRef&amp;gt;
      &amp;lt;OrderAttributes&amp;gt;
         &amp;lt;OrderAttributeName&amp;gt;Attribute1&amp;lt;/OrderAttributeName&amp;gt;
         &amp;lt;OrderAttributeValue&amp;gt;Value1&amp;lt;OrderAttributeValue&amp;gt;
         &amp;lt;OrderAttributeName&amp;gt;Attribute2&amp;lt;/OrderAttributeName&amp;gt;
         &amp;lt;OrderAttributeValue&amp;gt;Value2&amp;lt;OrderAttributeValue&amp;gt;
         &amp;lt;OrderAttributeName&amp;gt;Attribute3&amp;lt;/OrderAttributeName&amp;gt;
         &amp;lt;OrderAttributeValue&amp;gt;Value3&amp;lt;OrderAttributeValue&amp;gt;
      &amp;lt;/OrderAttributes&amp;gt;
   &amp;lt;/ORDER&amp;gt;
&amp;lt;/RECORD&amp;gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to extract the individual attributes to display in a table something like this:&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="20%"&gt;OrderDate&lt;/TD&gt;
&lt;TD width="20%"&gt;OrderRef&lt;/TD&gt;
&lt;TD width="20%"&gt;Attribute1&lt;/TD&gt;
&lt;TD width="20%"&gt;Attribute2&lt;/TD&gt;
&lt;TD width="20%"&gt;Attribute3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="20%"&gt;21-11-2022&lt;/TD&gt;
&lt;TD width="20%"&gt;12345678&lt;/TD&gt;
&lt;TD width="20%"&gt;Value1&lt;/TD&gt;
&lt;TD width="20%"&gt;Value2&lt;/TD&gt;
&lt;TD width="20%"&gt;Value3&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried SPATH but not able to pull Attribute1 &amp;amp; Value1 pair as there are multiple instances of OrderAttributeName &amp;amp; OrderAttributeValue tags, so have hit the buffers.&lt;/P&gt;
&lt;P&gt;Any suggestions on how can I make it work?&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 14:28:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-attribute-name-value-pair-from-XML/m-p/621620#M216075</guid>
      <dc:creator>Astro</dc:creator>
      <dc:date>2022-11-22T14:28:03Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting multiple attribute name value pair from XML?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-attribute-name-value-pair-from-XML/m-p/621631#M216078</link>
      <description>&lt;P&gt;You can use spath then foreach to make the attribute/name values to their respective fields.&lt;/P&gt;&lt;P&gt;Note your original XML is malformed - you are missing "/" character on closing OrderAttributeValue and you have an extra &amp;gt; after your OrderRef.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="&amp;lt;RECORD&amp;gt;
   &amp;lt;ORDER&amp;gt;
      &amp;lt;OrderDate&amp;gt;21-11-2022&amp;lt;/OrderDate&amp;gt;
      &amp;lt;OrderRef&amp;gt;12345678&amp;lt;/OrderRef&amp;gt;
      &amp;lt;OrderAttributes&amp;gt;
         &amp;lt;OrderAttributeName&amp;gt;Attribute1&amp;lt;/OrderAttributeName&amp;gt;
         &amp;lt;OrderAttributeValue&amp;gt;Value1&amp;lt;/OrderAttributeValue&amp;gt;
         &amp;lt;OrderAttributeName&amp;gt;Attribute2&amp;lt;/OrderAttributeName&amp;gt;
         &amp;lt;OrderAttributeValue&amp;gt;Value2&amp;lt;/OrderAttributeValue&amp;gt;
         &amp;lt;OrderAttributeName&amp;gt;Attribute3&amp;lt;/OrderAttributeName&amp;gt;
         &amp;lt;OrderAttributeValue&amp;gt;Value3&amp;lt;/OrderAttributeValue&amp;gt;
      &amp;lt;/OrderAttributes&amp;gt;
   &amp;lt;/ORDER&amp;gt;
&amp;lt;/RECORD&amp;gt;"

| spath
| rename RECORD.ORDER.* as *
| foreach 0 1 2 3 4  [ eval f=mvindex('OrderAttributes.OrderAttributeName', &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;), {f}=mvindex('OrderAttributes.OrderAttributeValue', &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;) ]
| table OrderDate OrderRef Attribute*&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;The numbers in the foreach will determine how many possible attributes this can handle&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2022 22:50:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-attribute-name-value-pair-from-XML/m-p/621631#M216078</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2022-11-21T22:50:28Z</dc:date>
    </item>
  </channel>
</rss>

