Getting Data In

How to extract all children in xml?

matstap
Communicator

I have part of an xml file which looks like this:

<Field name="Name1" type="string" length="16">
    <Comments>
        <p/>Value 1
    </Comments>
</Field>
<Field name="Name2" type="string" length="8">
    <Comments>
        <p/>Value 2:
        <ul>
           <li>Value 2a</li>
           <li>Value 2b</li>
        </ul>
    </Comments>

I am trying to make a field called Comments with all the text inside the Comments tag for each Field tag.
Example:
For Name1, Comments="Value 1"
For Name2, Comments="Value 2: Value 2a Value2b

In the case of Name2, how do I capture the list as well as the paragraph?

I have tried spath path=...Field.Comments but that only captures the <p> .

0 Karma
1 Solution

cmerriman
Super Champion

have you tried xpath instead?

https://docs.splunk.com/Documentation/SplunkCloud/6.6.3/SearchReference/Xpath

it still might be tricky to get all of them under comments, but what if you just tried |xpath outfield=Comments "//Field/Comments"

View solution in original post

0 Karma

cmerriman
Super Champion

have you tried xpath instead?

https://docs.splunk.com/Documentation/SplunkCloud/6.6.3/SearchReference/Xpath

it still might be tricky to get all of them under comments, but what if you just tried |xpath outfield=Comments "//Field/Comments"

0 Karma

matstap
Communicator

Thanks. That worked to capture everything inside the Comments. I then removed the tags to get my desired result: | rex field=Comments mode=sed "s/\<((\w|\/)+)\>//g"

0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...