Dashboards & Visualizations

How to keep multiple events in one XML file but pull the key-value pairs from each transaction line?

thesba
New Member

I have thousands of XML files which are being indexed in Splunk and I would like to extract values from the XML. The XML data contains product information and transactions every time a sale occurs. However, when I used xmlkv to extract the values from the XML, if there are multiple transactions, Splunk only sees the last key-value pair and disregards that multiple items were in the bucket/shopping cart. I've played with xmlsplit and reviewed the documents regarding splitting the XML file in the props.conf, however then each event would lose valuable information like the timestamp and location which isn't stored in each transactionline. An example of the data is below:

<JournalHeader>
</JournalHeader>
<SaleEvent>
  <TransactionDetailGroup>
    <TransactionLine status="normal">
      <ItemLine>
        <ItemCode>
          <POSCode>1001</POSCode>
        </ItemCode>
        <Description>Product A</Description>
      </ItemLine>
    </TransactionLine>
    <TransactionLine status="normal">
      <ItemLine>
        <ItemCode>
          <POSCode>1011</POSCode>
        </ItemCode>
        <Description>Product B</Description>
      </ItemLine>
    </TransactionLine>
    <TransactionLine status="normal">
      <ItemLine>
        <ItemCode>
          <POSCode>1021</POSCode>
        </ItemCode>
        <Description>Product C</Description>
      </ItemLine>
    </TransactionLine>
    <TransactionLine status="normal">
    ...
    </TransactionLine>
  </TransactionDetailGroup>
  <TransactionSummary>
...
  </TransactionSummary>
</SaleEvent>

If I do a table of 100 events and list the POSCode and Description, I would get 100 events with either 1001 & Product A or 1021 & Product C.

Is there a way to keep the event as a single event but drill down into each TransactionLine and pull the key-values from each?

Tags (4)
0 Karma

martin_mueller
SplunkTrust
SplunkTrust
0 Karma

jensonthottian
Contributor

So @thesba finally what is the solution you undertake?
Can you share the approach, I am also trying to parse through POS XML log files.

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Doing that with XML is a bit annoying... with JSON you can apply spath partially, mvexpand, and apply the second half of spath then. Here you can do something like this:

... | spath | eval temp = mvzip(Description, Qty) | mvexpand temp | rex field=temp "(?<Description>[^,]+),(?<Qty>[^,]+)" | fields - temp

That's assuming the description doesn't contain a comma.

0 Karma

thesba
New Member

spath is helpful, thank you!. What I'm trying to do is calculate sums on the purchased quantity and product. With spath the fields have values of

Qty
1
2
1

Description
Product A
Product B
Product C

How would I associate
Product A, Qty 1
Product B, Qty 2
Product C, Qty 1

So I could do a search on all events and determine total products sold during different time periods? I've tried using mvjoin and eval?

0 Karma
Get Updates on the Splunk Community!

Now Playing: Splunk Education Summer Learning Premieres

It’s premiere season, and Splunk Education is rolling out new releases you won’t want to miss. Whether you’re ...

The Visibility Gap: Hybrid Networks and IT Services

The most forward thinking enterprises among us see their network as much more than infrastructure – it's their ...

Get Operational Insights Quickly with Natural Language on the Splunk Platform

In today’s fast-paced digital world, turning data into actionable insights is essential for success. With ...