XML tag filtering

Hello,
i have an xml file. I use input codec multiline. My filter is an xml xpath filter and output is stdout.
I have a question about xml tag filtering.
The XML structure looks like this:

<service>
<Report>
<Properties>
<tag name="host-ip">127.0.0.1</tag>
<tag name="os">linux</tag>
<Rapport>
......
</Rapport>
</Properties>
</Report>
</service>

What i need to do, to filter the values 127.0.0.1 or linux of the tag with xpath? I tried different things like

"/service/Report/Properties/tag name='host-ip'/text()","host-ip",

but that brings an error.

Use an Xpath Tester/Evaluator tool online

The XPath expression

//tag[@name]/text()

will return

127.0.0.1
linux

the Path expression

//tag[@name='os']/text()

will return

linux

the XPath expression

//tag[@name='host-ip']/text()

will return

127.0.0.1

Then one would read all about the xml filter in logstash

1 Like

hope this xpath expression works for you,

"/service/Report/Properties/tag[@name='host-ip']/text()","host-ip"

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.