Splunk Search

How to print xpath results?

ThePony23
New Member

Hi,

I have added a directory full of following xml files into Splunk:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="MeasDataCollection.xsl" ?>
<!DOCTYPE mdc SYSTEM "MeasDataCollection.dtd">
<mdc xmlns:HTML="http://www.w3.org/TR/REC-xml">
<mfh>
<ffv>5</ffv>
<sn>DC=mars.com,g3SubNetwork=US,g3ManagedElement=USHSS01</sn>
<st>Netio</st>
...

I would like to print stats or use a chart based upon the /mdc/mfh/st element in the xml files. These files are from multiple sources, and have different "st" values. Here is what I have so far in my search string:

sourcetype="xml" | xpath "/mdc/mfh/st" outfield=st default="hello_world" | chart count(st) AS Platform by type

However, all I see as output is a table with "text/xsl" and "2" - ie. 2 results. I am expected something like "Netio" and "2". It seems like the xpath expression is not working? Any ideas? Is there a simple way to just print all the outfield values in plain text? Thanks in advance.

Tags (4)
0 Karma

john
Communicator

give right pathin source and append this code
|xmlkv|xpath "//mdc/mfh/st" outfield=st | stats values(st)

0 Karma

Drainy
Champion

Could you paste a complete sample of XML or a pastebin link to it please?

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...