# How to extract xml data?

**URL:** <https://discuss.elastic.co/t/how-to-extract-xml-data/82557>\
**Category:** Logstash\
**Created:** [April 17, 2017, 9:33am UTC](https://discuss.elastic.co/t/how-to-extract-xml-data/82557 "2017-04-17T09:33:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![laptop\_data](https://avatars.discourse-cdn.com/v4/letter/l/3e96dc/32.png) [@laptop\_data](https://discuss.elastic.co/u/laptop_data)\
**Post date:** [April 17, 2017, 9:33am UTC](https://discuss.elastic.co/t/how-to-extract-xml-data/82557/1 "2017-04-17T09:33:49Z")

</div>

Hi,

I have XML data shown below, how to extract it. Using XML filter.

```
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE> <?xml-stylesheet type="text/xsl"?> <osx start="1492328769" startstr="Linux Apr 16 13:16:09 2017" version="7.40" xmloutputversion="1.04"> <scaninfo type="syn" protocol="tcp" services="9000" services="1-9000"/> <verbose level="0"/> <debugging level="0"/> <taskprogress time="1492329125" percent="99.50" remaining="1" etc="1492329125"/> <host starttime="1492328777" endtime="1492329127"><status state="up" reason="echo-reply" reason_ttl="254"/> <address addr="192.168.1.1" addrtype="ipv4"/> <hostnames> <hostname name="google.com" type="user"/> </hostnames> <osmatch name="Linux" accuracy="94" line="94449"> <osclass type="general purpose" vendor="Linux" osfamily="" osgen="14" accuracy="94"> <cpe> cpe:/o:linux:linuxos:14 </cpe> </osclass> </osmatch> <distance value="1"/> <trace port="139" proto="tcp"> <hop ttl="1" ipaddr="192.168.1.1" rtt="83.00"/> </trace> <times srtt="82575" rttvar="5011" to="102619"/> </host> </osx>
```

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [April 18, 2017, 8:38am UTC](https://discuss.elastic.co/t/how-to-extract-xml-data/82557/2 "2017-04-18T08:38:38Z")

</div>

In what way are you finding the xml filter hard to use?

In what way do you want to extract the data? What is the desired result?

---

<div class="post-metadata">

**Author:** ![laptop\_data](https://avatars.discourse-cdn.com/v4/letter/l/3e96dc/32.png) [@laptop\_data](https://discuss.elastic.co/u/laptop_data)\
**Post date:** [April 20, 2017, 9:49am UTC](https://discuss.elastic.co/t/how-to-extract-xml-data/82557/3 "2017-04-20T09:49:58Z")

</div>

Hi @magnusbaeck, Thanks for your replay, I want to pass that data to kibana to visualize.  
I require column data from the xml. How to extract each single element from XML.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [April 20, 2017, 10:02am UTC](https://discuss.elastic.co/t/how-to-extract-xml-data/82557/4 "2017-04-20T10:02:23Z")

</div>

Okay. And have you tried using the xml filter and specifying the name of the field containing the XML data in the `source` option?

---

<div class="post-metadata">

**Author:** ![laptop\_data](https://avatars.discourse-cdn.com/v4/letter/l/3e96dc/32.png) [@laptop\_data](https://discuss.elastic.co/u/laptop_data)\
**Post date:** [April 20, 2017, 10:12am UTC](https://discuss.elastic.co/t/how-to-extract-xml-data/82557/5 "2017-04-20T10:12:46Z")

</div>

yes, i've written like

> filter {  
> xml {  
> source =\> "osx"  
> }  
> }

but it is not working

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [April 20, 2017, 10:15am UTC](https://discuss.elastic.co/t/how-to-extract-xml-data/82557/6 "2017-04-20T10:15:26Z")

</div>

And what does an example event look like? Use a `stdout { codec => rubydebug }` output to dump the raw resulting event.

---

<div class="post-metadata">

**Author:** ![laptop\_data](https://avatars.discourse-cdn.com/v4/letter/l/3e96dc/32.png) [@laptop\_data](https://discuss.elastic.co/u/laptop_data)\
**Post date:** [April 20, 2017, 10:18am UTC](https://discuss.elastic.co/t/how-to-extract-xml-data/82557/7 "2017-04-20T10:18:39Z")

</div>

> \<?xml version="1.0" encoding="UTF-8"?\>  
> \<!DOCTYPE\> \<?xml-stylesheet type="text/xsl"?\>  
> \<osx start="1492328769" startstr="Linux Apr 16 13:16:09 2017" version="7.40" xmloutputversion="1.04"\>  
> \<scaninfo type="syn" protocol="tcp" services="9000" services="1-9000"/\>  
> \<verbose level="0"/\>  
> \<debugging level="0"/\>  
> \<taskprogress time="1492329125" percent="99.50" remaining="1" etc="1492329125"/\>  
> \<host starttime="1492328777" endtime="1492329127"\>  
> \<status state="up" reason="echo-reply" reason\_ttl="254"/\> \<address addr="192.168.1.1" addrtype="ipv4"/\> \<hostnames\> \<hostname name="[google.com](http://google.com)" type="user"/\> \</hostnames\> \<osmatch name="Linux" accuracy="94" line="94449"\> \<osclass type="general purpose" vendor="Linux" osfamily="" osgen="14" accuracy="94"\> \<cpe\> cpe:/o:linux:linuxos:14 \</cpe\> \</osclass\> \</osmatch\> \<distance value="1"/\> \<trace port="139" proto="tcp"\> \<hop ttl="1" ipaddr="192.168.1.1" rtt="83.00"/\> \</trace\> \<times srtt="82575" rttvar="5011" to="102619"/\> \</host\> \</osx\>  
> [/quote]

This is my data and used the same stdout.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [April 20, 2017, 11:06am UTC](https://discuss.elastic.co/t/how-to-extract-xml-data/82557/8 "2017-04-20T11:06:41Z")

</div>

That's not what I asked for, but I think I know what the problem is anyway. Don't set the `source` option to "osx". The field where the XML data is stored is most likely named "message".

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 18, 2017, 11:06am UTC](https://discuss.elastic.co/t/how-to-extract-xml-data/82557/9 "2017-05-18T11:06:57Z")

</div>

Closed on May 18, 2017, 11:06am UTC

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