# XML parsing logstash, adding part of XML tags to an array per event

**URL:** <https://discuss.elastic.co/t/xml-parsing-logstash-adding-part-of-xml-tags-to-an-array-per-event/94827>\
**Category:** Logstash\
**Created:** [July 27, 2017, 3:40pm UTC](https://discuss.elastic.co/t/xml-parsing-logstash-adding-part-of-xml-tags-to-an-array-per-event/94827 "2017-07-27T15:40:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![g\_dev](https://avatars.discourse-cdn.com/v4/letter/g/91b2a8/32.png) [@g\_dev](https://discuss.elastic.co/u/g_dev)\
**Post date:** [July 27, 2017, 3:40pm UTC](https://discuss.elastic.co/t/xml-parsing-logstash-adding-part-of-xml-tags-to-an-array-per-event/94827/1 "2017-07-27T15:40:06Z")

</div>

I'm trying to parsing xml file using multiline, and inside the main tag(from mutiline pattern) I want another tag to add to an array

Issue --\> I'm not able to get \<INV\_HW\_STANDARD\_MODULES\> into an array and later I can use ruby on that for other processing.

Sample xml example:

![](https://us1.discourse-cdn.com/elastic/original/3X/a/5/a505b07ad6268153f2aa5b75aa58b32a3f5ed6c2.png)

logstash.conf:  
input {  
file  
{  
path =\> "/usr/local/src/files/Physical\_Inventory.xml"  
start\_position =\> "beginning"  
sincedb\_path =\> "/dev/null"  
codec =\> multiline  
{  
pattern =\> "^\s+\</INV\_NES\>"  
negate =\> true  
what =\> previous  
}  
}  
}

filter {  
#Extract the uniqueCollectionId from the file name  
grok {  
match =\> {"path" =\> "%{GREEDYDATA}/%{NUMBER:uniqueCollectionId}-%{GREEDYDATA}Physical\_Inventory.xml"}  
}

```
xml 
{
	source => "message"
    target => "xml_content"
    xpath => ["//INV_NETWORKS//INV_SITES//INV_NES//INV_HW_STANDARD_MODULES", "hardwareI"]  
}

split {
    add_field => {"Hardware" => "%{[xml_content][INV_HW_STANDARD_MODULES]}"}
}

#Add field platform, its same for all Mini-Link nodes
mutate {
    add_field => { "platform" => "Mini-Link"}
    add_field => { "isValidated" => false}
}

#Remove all unwanted fileds
mutate {
    remove_field => ["path", "message", "host", "@version"]
}

```

}

output {  
stdout {  
codec =\> rubydebug  
}  
}

I'm not able to get \<INV\_HW\_STANDARD\_MODULES\> into an array and later I can use ruby on that for other processing.

---

<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:** [August 5, 2017, 6:03pm UTC](https://discuss.elastic.co/t/xml-parsing-logstash-adding-part-of-xml-tags-to-an-array-per-event/94827/2 "2017-08-05T18:03:45Z")

</div>

Comment out all your filters and show us the result of your `stdout { codec => rubydebug }` output so we can see that the multiline codec is doing the right thing. I think your problems start there.

---

<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 2, 2017, 6:18pm UTC](https://discuss.elastic.co/t/xml-parsing-logstash-adding-part-of-xml-tags-to-an-array-per-event/94827/3 "2017-09-02T18:18:51Z")

</div>

Closed on September 2, 2017, 6:18pm UTC

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