- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
praspai
Path Finder
07-10-2018
05:18 AM
I want to extract XML field value ItemType and ItemNo from following XML. How can I build the Regular expression?
<impl:RetailItemList>
<impl:VoRetailItem>
<impl:ItemType>PPT</impl:ItemType>
<impl:ItemNo>123456</impl:ItemNo>
<impl:VoClassUnitKey>
<impl:ClassType>BU</impl:ClassType>
<impl:ClassUnitType>ST</impl:ClassUnitType>
<impl:ClassUnitCode>0001</impl:ClassUnitCode>
</impl:VoClassUnitKey>
</impl:VoRetailItem>
</impl:RetailItemList>
1 Solution
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

skoelpin

SplunkTrust
07-10-2018
05:47 AM
Try add this to your search
| rex ItemType>(?<ItemType>\w+)
| rex ItemNo>(?<ItemNo>\d+)
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

niketn
Legend
07-10-2018
06:51 AM
@praspai try the spath command for traversing xml or json:
| makeresults
| eval _raw="<impl:RetailItemList>
<impl:VoRetailItem>
<impl:ItemType>PPT</impl:ItemType>
<impl:ItemNo>123456</impl:ItemNo>
<impl:VoClassUnitKey>
<impl:ClassType>BU</impl:ClassType>
<impl:ClassUnitType>ST</impl:ClassUnitType>
<impl:ClassUnitCode>0001</impl:ClassUnitCode>
</impl:VoClassUnitKey>
</impl:VoRetailItem>
</impl:RetailItemList>"
| spath
Above extracts all the fields but you can traverse and extract specific nodes as per need as well.
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
| makeresults | eval message= "Happy Splunking!!!"
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
suryaconsultant
New Member
11-15-2018
04:10 AM
above code didn't work for me, can you pls help to understand what should be the issue
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

skoelpin

SplunkTrust
07-10-2018
05:47 AM
Try add this to your search
| rex ItemType>(?<ItemType>\w+)
| rex ItemNo>(?<ItemNo>\d+)
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

richgalloway

SplunkTrust
07-10-2018
05:25 AM
Before using regex, have you looked at the spath
and xpath
commands?
---
If this reply helps you, Karma would be appreciated.
If this reply helps you, Karma would be appreciated.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
praspai
Path Finder
07-10-2018
05:33 AM
I want to extract these values as fields and search will be based on it. I didn't find the way to define it while adding the data source. I looked into it but I thought I can use these commands only in search.
