# Parse XML

**URL:** <https://discuss.elastic.co/t/parse-xml/175150>\
**Category:** Logstash\
**Created:** [April 3, 2019, 9:46am UTC](https://discuss.elastic.co/t/parse-xml/175150 "2019-04-03T09:46:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vivek\_Sharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vivek_sharma/32/46948_2.png) [@Vivek\_Sharma](https://discuss.elastic.co/u/Vivek_Sharma)\
**Post date:** [April 3, 2019, 9:46am UTC](https://discuss.elastic.co/t/parse-xml/175150/1 "2019-04-03T09:46:33Z")

</div>

Hi

For data Order Event, below are the values that are coming in XML:

> OrderType : Direct  
> OrderDate : 20190401

But the XML contains the field name and field values in below format:

```
<OrderEvent>
<FieldName>OrderType</FieldName>
<FieldValue>Direct</FieldValue>
<FieldName>OrderDate</FieldName>
<FieldValue>20190401</FieldValue>
</OrderEvent>
</OrderEvent>

```

Had it been ordertype and order date in tags I would have fetched it easily but here these are embeded in FieldName and FieldValue tags.

If I need to fetch order date then how should I proceed.

Thanks

---

<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:** [April 3, 2019, 2:06pm UTC](https://discuss.elastic.co/t/parse-xml/175150/2 "2019-04-03T14:06:33Z")

</div>

```
    xml {
        store_xml => true
        target => "[@metadata]"
        source => "message"
    }
    ruby {
        code => '
            k = event.get("[@metadata][FieldName]")
            v = event.get("[@metadata][FieldValue]")
            k.each_index { |x|
                event.set(k[x], v[x])
            }
        '
    }
```

---

<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 1, 2019, 2:06pm UTC](https://discuss.elastic.co/t/parse-xml/175150/3 "2019-05-01T14:06:42Z")

</div>

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