Getting Data In

Ingestion of hierarchical XML logs

Ed11375
Explorer

I am trying to index hierarchical XML log files into Splunk. The file contains several groups of data linked by ID fields. I need to flatten out the data before indexing so queries can search the data as a flat table.

Here is an example of an XML log:

<?xml version="1.0" encoding="utf-8"?><FleetData dateCreated="2021-01-08T15:20:07.1046931Z" xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.cleverdevices.com/FleetManager"><Locations><Location><CustomerLocationId/><Deleted>false<... (T23)</Model><ObjectVersion>AAAAD5sp2kE=</ObjectVersion><OrganizationId>0</OrganizationId><VehicleTypeId>33</VehicleTypeId></VehicleType></VehicleTypes><Vehicles><Vehicle><Deleted>false</Deleted><EffectiveOrganizationId>0</EffectiveOrganizationId><InService>true</InService><LicensePlate/><LocationId>14</LocationId><ModelYear>2019</ModelYear><ObjectVersion>AAAAD5u2qqg=</ObjectVersion><OrganizationId>-1</OrganizationId><VehicleId>3201</VehicleId><VehicleNumber>1</VehicleNumber><VehicleTypeId>-1</VehicleTypeId><Vin/></Vehicle><Vehicle><Deleted>false</Deleted><EffectiveOrganizationId>-1</EffectiveOrganizationId><InService>true</InService><LicensePlate/><LocationId>32</LocationId><ModelYear>2017</ModelYear><ObjectVersion>AAAAD5u3+Os=</ObjectVersion><OrganizationId>-1</OrganizationId><VehicleId>2702</VehicleId><VehicleNumber>10</VehicleNumber><VehicleTypeId>33</VehicleTypeId><Vin/></Vehicle></Vehicles></FleetData>

The resulting index should look like this:

dateCreatedVehicleIdBusToolsBusTypeLocationNameVehicleInServiceVehicleDeleted
2021-01-08T15:20:07.10469313201-1OrangeTrueFalse
2021-01-08T15:20:07.1046931270228CMFTrueFalse

 

I have searched the Splunk documentation and the Internet but cannot find any information on how to index these types of files. Any assistance with this would be greatly appreciated.

Labels (1)
0 Karma
1 Solution

to4kawa
Ultra Champion
index=_internal | head 1 | fields _raw
| eval _raw="<?xml version=\"1.0\" encoding=\"utf-8\"?><FleetData dateCreated=\"2021-01-08T15:20:07.1046931Z\" xmlns:a=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.cleverdevices.com/FleetManager\"><Locations><Location><CustomerLocationId/><Deleted>false<... (T23)</Model><ObjectVersion>AAAAD5sp2kE=</ObjectVersion><OrganizationId>0</OrganizationId><VehicleTypeId>33</VehicleTypeId></VehicleType></VehicleTypes><Vehicles><Vehicle><Deleted>false</Deleted><EffectiveOrganizationId>0</EffectiveOrganizationId><InService>true</InService><LicensePlate/><LocationId>14</LocationId><ModelYear>2019</ModelYear><ObjectVersion>AAAAD5u2qqg=</ObjectVersion><OrganizationId>-1</OrganizationId><VehicleId>3201</VehicleId><VehicleNumber>1</VehicleNumber><VehicleTypeId>-1</VehicleTypeId><Vin/></Vehicle><Vehicle><Deleted>false</Deleted><EffectiveOrganizationId>-1</EffectiveOrganizationId><InService>true</InService><LicensePlate/><LocationId>32</LocationId><ModelYear>2017</ModelYear><ObjectVersion>AAAAD5u3+Os=</ObjectVersion><OrganizationId>-1</OrganizationId><VehicleId>2702</VehicleId><VehicleNumber>10</VehicleNumber><VehicleTypeId>33</VehicleTypeId><Vin/></Vehicle></Vehicles></FleetData>"
| spath
| spath FleetData.Locations.Location.Deleted.Vehicles.Vehicle output=Vehicles
| stats values("FleetData{@*}") as * by Vehicles
| spath input=Vehicles
| fields - Vehicles
| table dateCreated VehicleId VehicleTypeId LocationId InService Deleted

View solution in original post

to4kawa
Ultra Champion
index=_internal | head 1 | fields _raw
| eval _raw="<?xml version=\"1.0\" encoding=\"utf-8\"?><FleetData dateCreated=\"2021-01-08T15:20:07.1046931Z\" xmlns:a=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.cleverdevices.com/FleetManager\"><Locations><Location><CustomerLocationId/><Deleted>false<... (T23)</Model><ObjectVersion>AAAAD5sp2kE=</ObjectVersion><OrganizationId>0</OrganizationId><VehicleTypeId>33</VehicleTypeId></VehicleType></VehicleTypes><Vehicles><Vehicle><Deleted>false</Deleted><EffectiveOrganizationId>0</EffectiveOrganizationId><InService>true</InService><LicensePlate/><LocationId>14</LocationId><ModelYear>2019</ModelYear><ObjectVersion>AAAAD5u2qqg=</ObjectVersion><OrganizationId>-1</OrganizationId><VehicleId>3201</VehicleId><VehicleNumber>1</VehicleNumber><VehicleTypeId>-1</VehicleTypeId><Vin/></Vehicle><Vehicle><Deleted>false</Deleted><EffectiveOrganizationId>-1</EffectiveOrganizationId><InService>true</InService><LicensePlate/><LocationId>32</LocationId><ModelYear>2017</ModelYear><ObjectVersion>AAAAD5u3+Os=</ObjectVersion><OrganizationId>-1</OrganizationId><VehicleId>2702</VehicleId><VehicleNumber>10</VehicleNumber><VehicleTypeId>33</VehicleTypeId><Vin/></Vehicle></Vehicles></FleetData>"
| spath
| spath FleetData.Locations.Location.Deleted.Vehicles.Vehicle output=Vehicles
| stats values("FleetData{@*}") as * by Vehicles
| spath input=Vehicles
| fields - Vehicles
| table dateCreated VehicleId VehicleTypeId LocationId InService Deleted

Ed11375
Explorer
Great. That works. Thank you.
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...

Design, Compete, Win: Submit Your Best Splunk Dashboards for a .conf26 Pass

Hello Splunkers,  We’re excited to kick off a Splunk Dashboard contest! We know that dashboards are a primary ...

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...