# Parse xml with logstash

**URL:** <https://discuss.elastic.co/t/parse-xml-with-logstash/193910>\
**Category:** Logstash\
**Created:** [August 6, 2019, 3:08am UTC](https://discuss.elastic.co/t/parse-xml-with-logstash/193910 "2019-08-06T03:08:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wzxmt\_l](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wzxmt_l/32/46888_2.png) [@wzxmt\_l](https://discuss.elastic.co/u/wzxmt_l)\
**Post date:** [August 6, 2019, 3:08am UTC](https://discuss.elastic.co/t/parse-xml-with-logstash/193910/1 "2019-08-06T03:08:15Z")

</div>

Hi All,Here is my xml,I want to parse this xml, how can I parse it?

\<?xml version="1.0" encoding="UTF-8"?\>

\<holding\_stock msgnum="3480"\>  
\<user\_id\>10028603\</user\_id\>  
\*\*\*\*\*\*\*\*  
\<pos\_str\>0\</pos\_str\>  
\<request\_num\>1000\</request\_num\>  
0  
\</holding\_stock\>

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [August 6, 2019, 12:31pm UTC](https://discuss.elastic.co/t/parse-xml-with-logstash/193910/2 "2019-08-06T12:31:02Z")

</div>

If you ingest that as a single event then you can parse it using an xml filter

```
xml { source => "message" target => "theXML" }

```

results in

```
    "theXML" => {
         "msgnum" => "3480",
        "content" => [
        [0] "\n",
        [1] "\n ******** \n",
        [2] "\n",
        [3] "\n0\n"
    ],
        "user_id" => [
        [0] "10028603"
    ],
        "pos_str" => [
        [0] "0"
    ],
    "request_num" => [
        [0] "1000"
    ]
},
```

---

<div class="post-metadata">

**Author:** ![wzxmt\_l](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wzxmt_l/32/46888_2.png) [@wzxmt\_l](https://discuss.elastic.co/u/wzxmt_l)\
**Post date:** [August 7, 2019, 1:29am UTC](https://discuss.elastic.co/t/parse-xml-with-logstash/193910/3 "2019-08-07T01:29:40Z")

</div>

Thank you, add xpath to parse out what I want!

---

<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:** [September 4, 2019, 1:29am UTC](https://discuss.elastic.co/t/parse-xml-with-logstash/193910/4 "2019-09-04T01:29:47Z")

</div>

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